Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 仅更新附加实体的某些字段_Entity Framework - Fatal编程技术网

Entity framework 仅更新附加实体的某些字段

Entity framework 仅更新附加实体的某些字段,entity-framework,Entity Framework,我使用的是.NET3.5SP1。我有实体“AppUser”: public class AppUser : System.Data.Objects.DataClasses.EntityObject{ public int Uid {get; set;} public string UserName {get; set;} public string Password {get; set;} public DateTime LastLogin {get; set;}

我使用的是.NET3.5SP1。我有实体“AppUser”:

public class AppUser : System.Data.Objects.DataClasses.EntityObject{   
 public int Uid {get; set;}   
 public string UserName {get; set;}   
 public string Password {get; set;}   
 public DateTime LastLogin {get; set;}   
 public string Name {get; set;}   
 public string Address {get; set;}
 public string Comment {get; set;} 
 ...........   
} 
要更新附件的所有字段,请执行以下操作:

   public void Update(AppUser updateUser) {
    AppUser user = ctx.AppUserSet.Where(u => u.UserId == userId).FirstOrDefault();
    //This will update ALL fields
    ctx.ApplyPropertyChanges(user.EntityKey.EntitySetName, updateUser);
    ctx.SaveChanges();   
    }  
我想更新除密码和LastLogin之外的所有字段。我可以更新单个字段,但对于具有大量字段的实体来说会很麻烦

请告诉我,实现这一目标的最佳方式是什么


谢谢。

我认为您不需要额外的编程工作就可以直接使用EF实现这一点

有三种可能性:

  • 通过视图更新
  • 使用存储过程进行更新
  • 更改数据模型,使密码和lastlogin位于一对一关系的单独表中

所有这些都需要额外的编程工作。

在EDMX/model中将这两个属性的setter更改为private