none
Conflicting changes detected. This may happen when trying to insert multiple entities with the same key.

    Question

  • I have opened an existing recode

    First time I am able to save the data

    Second time the same cotext and try to save the data getting Exception.

    (Conflicting changes detected. This may happen when trying to insert multiple entities with the same key)

    How can I handle multiple Entities during save and added new record

    How can I find what are the entities going to save.

    Common.MyContext.DBContext.ObjectStateManager.ChangeObjectState(_projHeader, EntityState.Modified);

     

    Common.MyContext.DBContext.SaveChanges();

     

    Common. MyContext.DBContext.DetectChanges(); then also I am getting issue.

     

    Can you please suggest some good solution for that

     


    Wednesday, June 22, 2011 8:38 AM

Answers

  • Hi Jeeva,

    Welcome!

    Each entity has EntityStates, so you can find the Added or Updated entities by their states

    context.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added| System.Data.EntityState.Unchanged);
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 23, 2011 5:28 AM

All replies

  • Hi Jeeva,

    Welcome!

    Each entity has EntityStates, so you can find the Added or Updated entities by their states

    context.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added| System.Data.EntityState.Unchanged);
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 23, 2011 5:28 AM
  • Hi Jeeva,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 30, 2011 6:46 AM