IncludeFilter 多个级别不起作用

IncludeFilter multiple levels not working

此 IncludeFilter 和包含多个级别时遇到问题。我正在使用 Entity Framework 6 Plus。

这是他们在 Load multiple levels 标题下 https://entityframework-plus.net/query-include-filter 提供的示例。

这行得通,但是 returns 保修记录比我想要的多。

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();
  • 您不能将 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();

This doesn't work at all because apparently with IncludeFilter you have to include a where clause

不,你没有。