Entity attachment issues in LINQ

后端 未结 3 1908
执念已碎
执念已碎 2020-12-10 11:38

I am trying to attach a LINQ entity to the data context after I receive it from a form POST. However, all I get is the following exception:

An entity can onl         


        
相关标签:
3条回答
  • 2020-12-10 12:16

    I solved by setting UpdateCheck=Never to my property in .Dbml file and context.entity.Attach(entity, true);

    0 讨论(0)
  • 2020-12-10 12:17

    In the LinqToSQL designer set all of the Update Checks to Never and when you attach call it like so:

     context.entity.Attach(entity, true);
    

    Alternatively, you could also grab the entity from the db and change it using the data from the POSTed entity, then submit that as a change.

    0 讨论(0)
  • Try following:

    dataContext.People.Attach(person);
    dataContext.Refresh(RefreshMode.KeepCurrentValues, person);
    dataContext.SubmitChanges();
    
    0 讨论(0)
提交回复
热议问题