检索发票时检索发票详细信息

时间:2016-07-05 21:04:15

标签: c# .net linq dynamics-crm-2011 dynamics-crm-2016

我有这个简单的LINQ to CRM查询:




  //检索与周期相关的所有发票...
 List<发票> invoiceCycleInvoices = ctx.InvoiceSet.Where(x => x.new_invoice_cycle_invoicesid.Id == invoiceCycle.Id
&& x.new_erpsync == false
&& x.StateCode!= InvoiceState.Canceled ).ToList();
  




通常, ToList 调用会提取延迟加载忘记的所有相关信息,但是 Invoice 中有一个名为 invoice_details 的属性,该属性始终为null。





如何填充它一举?




2 个答案:

答案 0 :(得分:1)

使用LoadProperty访问实体关系。

foreach (var invoice in invoiceCycleInvoices)
{
    ctx.LoadProperty(invoice, "invoice_details");
    var invoiceDetail = invoice.GetRelatedEntity<Entity>("invoice_details");
}

答案 1 :(得分:0)

应该是:

List<Invoice> invoiceCycleInvoices = ctx.InvoiceSet
    .Where(x => x.new_invoice_cycle_invoicesid.Id == invoiceCycle.Id
        && x.new_erpsync == false
        && x.StateCode != InvoiceState.Canceled)
    .Include(x => x.invoice_details)
    .ToList();