Does anyone knows easiest way to solve "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."?? I am trying add new record, this error triggers after EmployeePersonalService.Add(employeePersonal)...
Inside the Add method...
m_db.EmployeePersonalRows.InsertOnSubmit(empPer);
m_db.SubmitChanges();
Never encountered this error before...
Remember to click “Mark as Answer” on the post, if it helps you
Thanks for the info bloggernext, I have seen the second link and it does not work for me that approach, having compile error using this.Employee = default(EntityRef(Employee));
But I found the source of problem for this error, I am assigning Employee object retrieve from different select process to the EmployeePersonal.Employee object which is not supported.
I have resolved this problem, hopefully no more other linq problems.
Remember to click “Mark as Answer” on the post, if it helps you
den2005
Participant
875 Points
477 Posts
Linq problem: ...Attach or Add an entity that is not new, perhaps having been loaded from another...
Dec 01, 2009 08:07 AM|LINK
Hi,
Does anyone knows easiest way to solve "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."?? I am trying add new record, this error triggers after EmployeePersonalService.Add(employeePersonal)...
Inside the Add method...
m_db.EmployeePersonalRows.InsertOnSubmit(empPer);
m_db.SubmitChanges();
Never encountered this error before...
bloggernext
Contributor
2580 Points
481 Posts
Re: Linq problem: ...Attach or Add an entity that is not new, perhaps having been loaded from ano...
Dec 01, 2009 09:53 AM|LINK
check these links
http://geekswithblogs.net/michelotti/archive/2007/12/25/117984.aspx
http://weblogs.asp.net/omarzabir/archive/2007/12/08/linq-to-sql-how-to-attach-object-to-a-different-data-context.aspx
den2005
Participant
875 Points
477 Posts
Re: Linq problem: ...Attach or Add an entity that is not new, perhaps having been loaded from ano...
Dec 02, 2009 12:52 AM|LINK
Thanks for the info bloggernext, I have seen the second link and it does not work for me that approach, having compile error using this.Employee = default(EntityRef(Employee));
But I found the source of problem for this error, I am assigning Employee object retrieve from different select process to the EmployeePersonal.Employee object which is not supported.
I have resolved this problem, hopefully no more other linq problems.