左联接的查询语法不包括所有导航属性

时间:2018-11-06 10:01:33

标签: linq ef-code-first

我正在使用Ef Core version 1.1.2,我有这样的方法:

var query = _context.OrderItems
            .Include(ff => ff.ProductPackageOrderItem).ThenInclude(ff => ff.ProductPackage)
            .ThenInclude(ff => ff.Product)
            .Include(ff => ff.ChildrenOrderItems)
            .Include(ff => ff.ServiceOrderItem)
            .ThenInclude(ff => ff.CustomerService).ThenInclude(ff => ff.Package)
            .Include(ff => ff.InvoiceItems)
            .ThenInclude(ff => ff.InvoiceItem)
            .ThenInclude(ff => ff.InvoiceItemDiscountLogs)
            .Include(ff => ff.InvoiceItems)
            .ThenInclude(ff => ff.InvoiceItem)
            .ThenInclude(ff => ff.InvoiceItemTaxLogs)
            .Where(dd =>
                dd.OrderId == orderId);
        return query.ToList();

由于我在此版本中使用的一个错误,我抛出了一个异常,现在我想将其更改为Linq查询,要做到这一点,我有这个问题,但是它有一些问题

 var result = (from oi in DataContext.OrderItems.Include(o => o.ChildrenOrderItems)
                      .Include(ff => ff.InvoiceItems).ThenInclude(ff => ff.InvoiceItem).ThenInclude(ff => ff.InvoiceItemDiscountLogs)
                      join soi in DataContext.ServiceOrderItems.Include(ff => ff.CustomerService).ThenInclude(ff => ff.Package).ThenInclude(ff => ff.Product) on oi.Id equals soi.OrderItemId
                      join ii in DataContext.OrderItemInvoiceItems.Include(ff => ff.InvoiceItem).ThenInclude(ff => ff.InvoiceItemDiscountLogs) on oi.Id equals ii.OrderItemId
                      join oiii in DataContext.OrderItemInvoiceItems.Include(ff => ff.InvoiceItem).ThenInclude(ff => ff.InvoiceItemTaxLogs) on oi.Id equals oiii.OrderItemId
                      join ppoi in DataContext.ProductPackageOrderItems.DefaultIfEmpty().Include(ff => ff.ProductPackage).ThenInclude(ff => ff.Product) on oi.Id equals ppoi.OrderItemId
                      where oi.OrderId == orderId && oi.Type == OrderItemType.CustomerService && !oi.IsDeleted
                      && !oi.ServiceOrderItem.IsDeleted
                      && !oi.ServiceOrderItem.CustomerService.IsDeleted
                      && oi.ServiceOrderItem.CustomerService.Id == customerServiceId
                     select oi).ToList();
        return result;

1。它不返回任何内容,因为某些记录没有任何ProductPackageOrderItems。 2。InvoiceItemTaxLogsInvoiceItemDiscountLogs为空,尽管它们在数据库中有数据。

0 个答案:

没有答案