【发布时间】:2012-04-26 22:42:49
【问题描述】:
首先使用实体框架代码,我有类似的东西:
public class Foo
{
public int Id { get; set; }
public List<Bar> Bars { get; set; }
}
Foo foo = (from f in ctx.Foos.Include("Bars") where f.Id == 42 select f).Single();
// At this point foo.Bars is populated
ctx.Entry(foo).State = EntityState.Detached;
// At this point foo.Bars is an empty List
为什么分离一个对象会导致它的属性public List<string> Bars被清空?
分离可能具有许多属性的对象的正确过程是什么?
【问题讨论】:
标签: entity-framework-4 ef-code-first