此IncludeFilter出现问题,并且包含多个级别。我正在使用Entity Framework 6 Plus。
这是他们在Load multiple levels
标题下提供https://entityframework-plus.net/query-include-filter的示例。
这可行,但是返回的保修记录比我想要的还要多。
db.Application.Where(x => x.ApplicationId == applicationId)
.Include(x => x.Lienholder)
.Include(x => x.Warranty.Select(y => y.Coverage.CoverageGroup))
.Include(x => x.Vehicle)
.Include(x => x.Vendor)
.First();
此方法有效,但是.Coverage
为空,但它是与示例最接近的一个。
db.Application.Where(x => x.ApplicationId == applicationId)
.Include(x => x.Lienholder)
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
)
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
).Select(y => y.Coverage.CoverageGroup))
.Include(x => x.Vehicle)
.Include(x => x.Vendor)
.First();
这根本不起作用,因为显然IncludeFilter
中您必须包含where子句
db.Application.Where(x => x.ApplicationId == applicationId)
.Include(x => x.Lienholder)
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
).Select(y => y.Coverage.CoverageGroup))
.Include(x => x.Vehicle)
.Include(x => x.Vendor)
.First();
此方法有效,但它并不急于加载Coverage
db.Application.Where(x => x.ApplicationId == applicationId)
.Include(x => x.Lienholder)
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
)
.Include(x => x.Vehicle)
.Include(x => x.Vendor)
.First();
答案 0 :(得分:2)
Include
与IncludeFilter
或IncludeOptimized
混合使用。IncludeFilter
在您最近的示例中,您错过了“ Y.Coverage”
目前是该库的限制。
这是您要找的东西:
db.Application.Where(x => x.ApplicationId == applicationId)
.IncludeFilter(x => x.Lienholder)
.IncludeFilter(x => x.Warranty.Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
))
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
).Select(y => y.Coverage))
.IncludeFilter(x => x.Warranty.Where(z => true).Where(z =>
z.WarrantyStatusId == 2 ||
z.WarrantyStatusId == 3 ||
z.WarrantyStatusId == 8 ||
z.WarrantyStatusId == 10
).Select(y => y.Coverage.CoverageGroup)))
.IncludeFilter(x => x.Vehicle)
.IncludeFilter(x => x.Vendor)
.First();
这根本不起作用,因为显然必须使用IncludeFilter包含where子句
不,您没有。