简体   繁体   中英

Can't include a virtual navigational property

In my model (auto-generated), I can see:

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

However, when I try include the product into the returned set (since I'm going to need some values of it later on), there's nothing provided after intellisense.

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

I re-generated the model and re-run the T4 scripts. Inclusion of the other entities work as supposed to. Can't see what I might be doing wrong.

I suspect your forgot to add

using System.Data.Entity;

so you're not able to use the Include overload taking an expression as parameter that is provided by the System.Data.Entity.QueryableExtensions class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM