You must Sign In to post a response.
  • Category: LINQ

    Attach entity fron existing context to new context (Urgent)

    Hi all,
    In my application, employee object called as follows,

    personalModel.Domain.EmployeeDetail emp = new personalModel.Domain.EmployeeDetail();
    theUc = new personalUC.PersonalDetailsUC();
    emp = theUc.GetEmployeeDetails(employeeNo);

    The above code works as required.

    There is another object called objMemberhip holds the relationship with above emp object.
    Before call membership save method emp object attach to the objMemberhip as follows,

    objMemberhip.EmployeeDetail = emp;
    theUc.SaveMembership(objMemberhip, Session["user"].ToString());

    But above save method throws following error,
    "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported."

    Any help
  • #764272

    Hai Chaminda,
    As per the error description, "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.", it seems that you are creating new context inside the entity which is making the issue.
    You should not create the new instnace of the contetx class inside the entity and assign it.
    Hope it will be helpful to you.


    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • Sign In to post your comments