Hi there,
One of our team member has wrongly mapped "Choose Product" field on opportunityproduct entity while importing the data. We realized it later and we are trying to update the field with actual Products from product entity.
Here is the code that we are using to update the "choose product" field.
Entity entity = new Entity("opportunityproduct")
{
Id = new Guid(dr["(Do Not Modify) Opportunity Product"].ToString())
};
entity["productid"] = new EntityReference("product", new Guid(dr["productid"].ToString()));
_orgService.Update(entity);
But for some reason, we are getting "Entity Reference cannot have Id and Key Attributes empty" error. Below the stack trace.
System.ServiceModel.FaultException`1
HResult=0x80131501
Message=Entity Reference cannot have Id and Key Attributes empty.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.<>c__DisplayClass38_0.<UpdateCore>b__0()
at Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient`1.ExecuteAction(Action action)
at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.UpdateCore(Entity entity)
at Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient.Update(Entity entity)
at ConsoleApp2.Program.Main(String[] args) in C:\ConsoleApp2\Program.cs:line 28
Can somebody please help if i am doing anything wrong.
Thanks,
Venu