IMPORTANT: MAJOR BREAKING CHANGE COMING SOON

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子句

不,你沒有。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因