none
请问LINQ TO SQL 中 更新方法如何简化 RRS feed

  • 问题

  • public void UpdateUser(user theUser)
        {
          if (theUser == null)
            return;
    
          user newUser = db.user.SingleOrDefault(x => x.userid == theUser.userid);
          if (newUser != null)
          {
            newUser.adminid = theUser.adminid;
            newUser.avatar = theUser.avatar;
            newUser.birthday = theUser.birthday;
            newUser.credits = theUser.credits;
            newUser.digestposts = theUser.digestposts;
            newUser.email = theUser.email;
            newUser.gender = theUser.gender;
            newUser.groupid = theUser.groupid;
            newUser.lastip = theUser.lastip;
            newUser.location = theUser.location;
            newUser.newpmcount = theUser.newpmcount;
            newUser.nickname = theUser.nickname;
            newUser.posts = theUser.posts;
            newUser.qq = theUser.qq;
            newUser.realname = theUser.realname;
            newUser.showbirthday = theUser.showbirthday;
            newUser.showemail = theUser.showemail;
            newUser.showrealname = theUser.showrealname;
            newUser.signature = theUser.signature;
            newUser.status = theUser.status;
            newUser.avatar = theUser.avatar;
            newUser.lastactivity = theUser.lastactivity;
            db.SubmitChanges();
          }
        }
    

    类似这类的更新,都得重新赋值吗?有没有简单的方法。

    在LINQ TO ENTITY中好像有ApplyCurrentValues这类的方法。不知道LINQ TO SQL里怎么搞?

     

    2011年2月25日 8:25

答案

全部回复