本文整理汇总了C#中ServiceContext.AddRelatedObject方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.AddRelatedObject方法的具体用法?C# ServiceContext.AddRelatedObject怎么用?C# ServiceContext.AddRelatedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.AddRelatedObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Notify
//.........这里部分代码省略.........
if (salesOffice != null)
record.new_salesoffice = salesOffice.ToEntityReference();
if(plant != null)
record.new_plant = plant.ToEntityReference();
record.new_customeradviser = item.Invoice.new_customeradviser;
record.new_billingdate = item.Invoice.new_billingdate;
record.new_licenseplatenumber = item.Invoice.new_licenseplatenumber;
record.new_country = item.Invoice.new_country;
record.new_counterreading = item.Invoice.new_counterreading;
record.new_counterunit = item.Invoice.new_counterunit;
record.new_orderstatus = item.Invoice.new_orderstatus;
record.new_netvalue = item.Invoice.new_netvalue;
record.new_vehicleguid = item.Invoice.new_vehicleguid;
if (invoiceType != null)
record.new_invoicetype = invoiceType.ToEntityReference();
if (add)
context.AddObject(record);
else
context.UpdateObject(record);
//Invoice Detail
//We will nowdelete all line item s and readd them
//if we do not do this we will get duplicate records.
if (record.invoice_details != null)
{
foreach (InvoiceDetail detail in record.invoice_details)
context.DeleteObject(detail);
}
foreach (InvoiceDetail lineItem in item.InvoiceDetails)
{
InvoiceDetail detail = new InvoiceDetail();
//new_material
new_modelsalescode material = null;
if(detail.new_material != null)
{
material = (from m in context.new_modelsalescodeSet
where m.new_name == lineItem.new_material.Name
select m).FirstOrDefault();
}
//Plant
Territory detailPlant = null;
if (lineItem.new_plant != null)
{
entity = (from p in context.CreateQuery("territory")
where p["new_sapcode"] == lineItem.new_plant.Name
select p).FirstOrDefault();
if (entity != null)
detailPlant = entity.ToEntity<Territory>();
}
//Populate Invoice Detail
detail.LineItemNumber = lineItem.LineItemNumber;
detail.new_pricingreferencematerial = lineItem.new_pricingreferencematerial;
detail.new_lvhierno = lineItem.new_lvhierno;
if (material != null)
detail.new_material = material.ToEntityReference();
detail.new_materialgroup = lineItem.new_materialgroup;
detail.ProductDescription = lineItem.ProductDescription;
detail.IsPriceOverridden = lineItem.IsPriceOverridden;
detail.IsProductOverridden = lineItem.IsProductOverridden;
detail.new_description1 = lineItem.new_description1;
detail.new_itemcategory = lineItem.new_itemcategory;
detail.new_deleteitem = lineItem.new_deleteitem;
detail.Quantity = lineItem.Quantity;
detail.new_targetqtyuom = lineItem.new_targetqtyuom;
detail.new_baseunit = lineItem.new_baseunit;
detail.new_targetqtyuom = lineItem.new_targetqtyuom;
detail.new_division = lineItem.new_division;
detail.PricePerUnit = lineItem.PricePerUnit;
detail.new_salesunit = lineItem.new_salesunit;
if (detailPlant != null)
detail.new_plant = detailPlant.ToEntityReference();
detail.new_storagelocation = lineItem.new_storagelocation;
context.AddRelatedObject(record, new Relationship("invoice_details"), detail);
}
}
context.SaveChanges();
}
}