小编xxx*_*xxx的帖子

更新EF 4功能CTP 4分离的POCO

我正在尝试使用EF 4 CTP 4更新分离的POCO.

我的域类看起来像这样:

public class User {
  public int Id { get; set; }

  [Required, DisplayName("First Name")]
  public string FirstName { get; set; }

  [Required, DisplayName("Last Name")]
  public string LastName { get; set; }

  [ConcurrencyCheckAttribute, Timestamp]
  public byte[] DataVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在存储库中,我有以下内容:

public void SaveUser(User user) {
  if (user.Id > 0) {
   dbContext.Users.Attach(user);
  }
  else {
   dbContext.Users.Add(user);
  }
  dbContext.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

dbContext继承自DbContext.

我能够做插入很好,但附加不起作用.我运行Sql Profiler,没有为更新发送sql.

.net poco entity-framework-4

5
推荐指数
1
解决办法
1395
查看次数

标签 统计

.net ×1

entity-framework-4 ×1

poco ×1