0
我需要在程序中实现一个函数,该函数将提供警察使用实体框架的统计信息。图为数据库的结构: C#实体框架LINQ - 创建报告
我的问题是,我无法正常组织多个加入:
Users.Where(w => w.Region == 1321)
.Select(s => s.Id)
.Join(Added, x => x, y => y.UserId, (x, y) => new
{
UserId = x,
PersonId = y.PersonId,
Date = y.AddDate
})
.GroupJoin(Status, x => x.PersonId, y => y.PersonId, (x, y) => new
{
PersonPreviouslyConvicted = y.PersonPreviouslyConvicted,
PersonBum = y.PersonBum,
PersonJobless = y.Jobless,
}).Join(Photos...).Join(More tables...)
此外,还有一些要合并7桌和计数号码。在所有表中,外键是PersonId。所有需要包装ReportContainer类型的对象列表的结果。 ReportContainer如下:
public class ReportContainer
{
public string Name { get; set; } // City or District name
public int? SevenDays { get; set; } // Count of the 7 days by column Added.AddDate
public int? ThirtyDays { get; set; } // Count of the 30 days by column Added.AddDate
public int? Bum { get; set; } //Count Bum
public int? Photography { get; set; } //Count Photos
public int? PreviouslyConvicted { get; set; } //Count PreviouslyConvicted
public int? Jobless { get; set; } //Count Jobless
}
我会建议使用sql查询这7个表内连接ef会有一些性能影响。当你的数据增长时,它将会很有效率。 你也可以打破单个查询来优化EF。基准和优化是2做的最好方法 – Eldho