none
Cannot create new Record - EntityState must be set to null, Created (for Create message) or Changed (for Update message)

    Question

  • Hi Guys

    I am trying to use linq to perform CRUD actions against CRM 2011, all retrieves are working great but I am having some issues creating new records. I can successfully create new ACCOUNT & OPPORTUNITY records but I am unable to create a CustomerAddress or Contact record, example code can be seen below:

    The Exception is: "EntityState must be set to null, Created (for Create message) or Changed (for Update message)"

    Before you ask, yes I have tried setting entity.EntityState = null and entity.EntityState = EntityState.Created

     

     

    CustomerAddress newAddress = new CustomerAddress()

    {

    Name =

     

    "Test Add",

    Line1 =

     

    "Test Line 1",

    ParentId =

     

    new Microsoft.Xrm.Sdk.EntityReference(Contact.EntityLogicalName, parentRecordId),

    Id =

     

    Guid.NewGuid()

    };

    Any Help would be greatly appreciated, Thanks  

     

    Monday, 21 February 2011 7:20 PM

Answers

  • I think you've misunderstood the purpose of Linq to CRM.  It's only meant to retrieve data, not create/update/delete.  Ultimately it just maps to a queryexpression.  Unless there was a major change in direction with the 2011 linq support (which I haven't seen any mention of anywhere) then compliance rules of CRM still forbid direct data layer updates (even through linq).

    Send your C_UD through the CRM SDK.

    Wednesday, 23 February 2011 1:10 AM