检索发票时检索发票详细信息
Retrieve invoice details when retrieving invoices
我有这个简单的 LINQ to CRM 查询:
//retrieve all invoices associated to the cycle...
List<Invoice> 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
的 属性 始终为空。
如何一次性填充它?
应该是:
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();
使用 LoadProperty 访问实体关系。
foreach (var invoice in invoiceCycleInvoices)
{
ctx.LoadProperty(invoice, "invoice_details");
var invoiceDetail = invoice.GetRelatedEntity<Entity>("invoice_details");
}
我有这个简单的 LINQ to CRM 查询:
//retrieve all invoices associated to the cycle...
List<Invoice> 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
的 属性 始终为空。
如何一次性填充它?
应该是:
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();
使用 LoadProperty 访问实体关系。
foreach (var invoice in invoiceCycleInvoices)
{
ctx.LoadProperty(invoice, "invoice_details");
var invoiceDetail = invoice.GetRelatedEntity<Entity>("invoice_details");
}