我有一个 linq to sql 表/类,它使用 GUID 作为主键和外键。在分解一些以前有效的代码时出现了这个问题。
产生的异常是
“由于对象的当前状态,操作无效。”
我使用的过程是这样的:
aspnet_User user() = new aspnet_User();
aspnet_user.childTable = new childTable();
.. set some properties
user.Insert() -> my custom method
... @我的自定义方法
using (mycontext dc = new context() )
{
user.childTable.ID = (Guid)myNewlyCreatedGuid;
}
异常发生在赋值 childTable.set_UserId() 上。