【发布时间】:2014-02-20 23:33:59
【问题描述】:
我在 Visual Studio 2010 中使用 C# 中的 Entity Framework 4。
我有一个在存储库中使用的方法,它返回一个包含各种导航属性的对象集。直到最近,这种方法看起来像这样......
private IEnumerable<VRTSystem> GetSystems() {
return ctx
.Include(s => s.Customer.CustomerType)
.Include(s => s.VRTSystemProductConfigurations);
}
...其中 ctx 是泛型类型 VRTSystem 的 ObjectSet。 full 方法的 .Include() 比这多得多,但这足以说明问题。
这很好用,但是我需要添加一些代码以确保只返回 Active 标志设置为 true 的 VRTSystemProductConfigurations。按照通常针对这种情况给出的建议,我将代码更改为如下所示...
private IEnumerable<VRTSystem> GetSystems() {
return ctx
.Include(s => s.Customer.CustomerType)
.Include(s => s.VRTSystemProductConfigurations)
.Select(s => new {
System = s,
VRTSystemProductConfigurations = s.VRTSystemProductConfigurations.Where(pc => pc.Active)
})
.Select(s => s.System);
}
但是,这个新版本不包含任何导航属性,它们都是空的。
有人知道为什么吗?
【问题讨论】:
标签: c# entity-framework entity-framework-4