【问题标题】:Checking Parent Type TPT EF4检查父类型 TPT EF4
【发布时间】:2011-05-09 11:54:58
【问题描述】:

我在 EF4 中有一个带有抽象基类的 TPT 场景。

我需要对一组子类型进行 linq 查询,以从一种父类型的字段中获取值。

例如。

ThisChild = Children.Where(c. => c.Parent.OfType<Mother>.JewelleryCollection > 10).FirstOrDefault();

在这种情况下,Parent 是抽象类,而 Mother 是 Parent 的一种。 Mother 是唯一具有 JewelleryCollection 字段的类型。

上面的例子中断了,因为你不能使用 .OfType 方法。我怎样才能最好地构造这个查询?

谢谢。

【问题讨论】:

  • ObservableCollection Children = new ObservableCollection();

标签: c# linq entity-framework-4 parent table-per-type


【解决方案1】:

因为您是在 ObservableCollection 上运行查询,所以它是 Linq-to-objects,您可以在其中简单地使用转换:

ThisChild = Children.FirstOrDefault(c => 
    (c.Parent is Mother) && (((Mother)c.Parent).JewelleryCollection > 10));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-05
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多