我正在尝试更新用户信息,但收到错误。
控制器代码:
var User = (somr linq query).firstorDefault
linq查询的结果以我的Viewmodel的形式出现,我的viewModel类就像
public partial class UsersInformation
{
public TableUserAccount UserAccount { get; set; }
public uint OwnerId { get; set; }
public string CountryName { get; set; }
}
我正在尝试更新ViewModel UsersInformation
形式的数据User.LastLoginDT = DateTime.Now;
User.TermsnCondAcceptDtID = LatestTerms.Id;
User.TermsnCondAcceptDt = DateTime.Now;
UserAccountService.UpdateUserInfo(User); //Passing object to Service
服务中的更新代码:
private static void updateInfo(tableUserAccount object)
{
using (var con = new MyModelName())
{
con.Add(object);
con.SaveChanges();
}
}
错误讯息:
Object references between two different object scopes are not allowed.
The object 'Shared.Models.Tbluseraccount' is already managed by
'ObjectScopeImpl 0x1b' and was tried to be managed again by
'ObjectScopeImpl 0x1c OpenAccessRuntime.EnlistableObjectScope'.