我正在使用最新版本的EF Core,它无法正常加载导航属性。 假设以下实体类
public partial class Categories
{
public Categories()
{
Inventories = new HashSet<Inventories>();
}
public string CategoryId { get; set; }
public string Title { get; set; }
public virtual ICollection<Inventories> Inventories { get; set; }
}
public partial class Inventories
{
public Inventories()
{
OrderItems = new HashSet<OrderItems>();
}
public string InventoryId { get; set; }
..
public string CategoryId { get; set; }
public virtual Categories Category { get; set; }
}
以下操作无法将Category
实体附加到查询中:
var query = Db.Set<Inventories>();
//query.FirstOrDefault().Category is Null
query.Include(x=> x.Category);
//query.FirstOrDefault().Category is Null
query.Include("Category");
//query.FirstOrDefault().Category is Null
但是,如果我这样做,Lazy和Eager加载工作:
var query = Db.Set<Categories>();
var query2 = Db.Set<Inventories>();
//query2.FirstOrDefault().Category Has Value