Thank you for your help, I tried to add Select into my plugin, but kept getting failures. I eventually ended up with it looking like the below, but now I am told
The context is already tracking a different 'dds_opportunity_product_line' entity with the same identity
public static void UpdateOPLsOnchangeofOpty(Entity opportunity, IOrganizationService orgService)
{
var SplitdealOption = opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity");
using (OrganizationServiceContext orgContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(orgService))
{
var OProductLineItems = orgContext.CreateQuery("dds_opportunity_product_line").Where(p =>
p.GetAttributeValue<EntityReference>("dds_opportunity_name") == opportunity.ToEntityReference()).ToList<Entity>();
//var OPLIneed = (from dds_opportunity_product_line in orgContext.CreateQuery("dds_opportunity_product_line")
// where dds_opportunity_product_line["dds_opportunity_name"] == opportunity.ToEntityReference()
// select dds_opportunity_product_line).ToList<Entity>();
foreach (var OPLs in OProductLineItems)
//foreach (var OPLs in OPLIneed)
{
var retFields = orgService.Retrieve("dds_opportunity_product_line", OPLs.Id, new ColumnSet("dds_split_deal_opl", "dds_split_percent_opl", "dds_split_with_opl", "dds_opportunity_product_lineid" ));
if (opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity").Value == 1)
{
retFields["dds_split_deal_opl"] = SplitdealOption;
retFields["dds_split_percent_opl"] = 0.00;
retFields["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("ownerid");
orgContext.UpdateObject(retFields);
}
else
{
retFields["dds_split_deal_opl"] = SplitdealOption;
retFields["dds_split_percent_opl"] = opportunity.GetAttributeValue<decimal>("dds_split_percentage_on_opportunity");
retFields["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("dds_split_with");
orgContext.Attach(retFields);
orgContext.UpdateObject(retFields);
}
}
orgContext.SaveChanges();
}
}