How To Update EF 4 Entity In ASP.NET MVC 3?

后端 未结 6 2008
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-09 07:26

I have 2 projects - a class library containing an EDM Entity Framework model and a seperate ASP.NET MVC project.

I\'m having problems with how your suppose to edit and s

6条回答
  •  萌比男神i
    2021-02-09 07:51

    OK, after some trial and error, I look to have found a solution. Here is my updated Update method in the UserRepository:

    public void Update(User user)
    {
        using (this.Context)
        {
            var tempUser = new User { usr_id = user.usr_id };
    
            this.Context.Users.Attach(tempUser);
            this.Context.ApplyCurrentValues("Users", user);
            this.Context.SaveChanges();
        }
    }
    

    Some of other examples I tried were very close to the above, but just missed the mark.

提交回复
热议问题