如何更新对象上下文中的对象,包括其关系

时间:2013-08-28 10:16:27

标签: entity-framework ef-code-first entity-framework-5 code-first

我使用以下代码使用数据源中的数据更新对象上下文中的对象:

 public class Project
    {
      public string Id{get;set;}
      public string Name{get;set;}
    }
 public class People
    { 
      public string Id{get;set;}
      public string Name{get;set;}
      public IList<Project> ProjectList{get;set;}
    }

 ((System.Data.Entity.Infrastructure.IObjectContextAdapter)Orm).ObjectContext.Refresh(
            System.Data.Objects.RefreshMode.StoreWins, people);

它更新了人而不是ProjectList(导航属性),所以问题是: 如何更新对象及其关系?

1 个答案:

答案 0 :(得分:0)

据我所知,你不能像这样自动完成,Refresh仅适用于单个对象的原始属性。如果您需要额外的刷新,则需要遍历对象并刷新每个对象。

自然地,更好的方法是使用急切加载重新加载整个图形,如果你真的不需要保留对象,因为你正在刷新它们。