LINQ to SQl updating primary key field?
Posted
by Curtis White
on Stack Overflow
See other posts from Stack Overflow
or by Curtis White
Published on 2010-04-05T19:12:37Z
Indexed on
2010/04/05
20:43 UTC
Read the original article
Hit count: 223
I have a linq to sql table/class that uses a GUID as both a primary key and as foreign key. This problem came up when factoring some code that previously worked.
The exception generated is
"Operation is not valid due to the current state of the object."
The process I use is as such:
aspnet_User user() = new aspnet_User();
aspnet_user.childTable = new childTable();
.. set some properties
user.Insert() -> my custom method
... @ my custom method
using (mycontext dc = new context() )
{
user.childTable.ID = (Guid)myNewlyCreatedGuid;
}
The exception occurs on the assignment childTable.set_UserId().
© Stack Overflow or respective owner