【问题标题】:Can't include a virtual navigational property不能包含虚拟导航属性
【发布时间】:2015-12-23 11:29:58
【问题描述】:

在我的模型(自动生成)中,我可以看到:

public partial class Order
{
  public System.Guid OrderId { get; set; }
  ...
  public System.Guid ProductId { get; set; }
  public virtual Product Product { get; set; }
}

但是,当我尝试将产品包含到返回的集合中时(因为稍后我将需要它的一些值),在智能感知之后没有提供任何内容。

using (ModelContext context = new ModelContext())
  return context.Orders
    .Include(order=>order.???)
    .Where(order => order.Condition)
    .ToList();

我重新生成了模型并重新运行了 T4 脚本。包含其他实体按预期工作。看不出我做错了什么。

【问题讨论】:

    标签: c# linq include


    【解决方案1】:

    我怀疑你忘了添加

    using System.Data.Entity;
    

    因此您不能使用Include 重载,将表达式作为System.Data.Entity.QueryableExtensions 类提供的参数。

    【讨论】:

    • 哦,但我有它,就在那里。然后我重构了文件以将两个类拆分为每个自己的单独文件。而愚蠢的驴便便 Resharper 并没有将这些东西带到新文件中!善于观察细节,伙计。 +1!
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2013-11-18
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多