不允许在两个不同的对象范围之间进行对象引用

时间:2015-04-22 07:59:37

标签: c# asp.net-mvc telerik repository

我正在尝试更新用户信息,但收到错误。

控制器代码:

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'. 

0 个答案:

没有答案