IncludeFilter多个级别无效

entity-framework-6 entity-framework-plus

有这个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 ,但.Coverage为null,但它是与示例最接近的一个。

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();

一般承认的答案

  • 您不能将IncludeIncludeFilterIncludeOptimized混合使用。
  • 您需要在他自己的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子句

不,你没有。



许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow
这个KB合法吗? 是的,了解原因
许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow
这个KB合法吗? 是的,了解原因