首先使用实体框架代码,我有类似的东西:
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
明确且成功包含的属性被清空?
分离可能具有许多属性的对象的正确程序是什么?