“包含”扩展方法不适用于 LinqKit

Posted

技术标签:

【中文标题】“包含”扩展方法不适用于 LinqKit【英文标题】:"Include" extension method does not work with LinqKit 【发布时间】:2015-12-17 01:35:24 【问题描述】:

我有 2 节课:

public class Employee

    public int Id get;set;
    public string Name get;set;


public class Remuneration

    public int Id get;set;
    public Employee Employee get;set;
    public int Amount get;set;

普通查询:

return _context.Remunerations.Include("Employee")

完美运行

但是当我使用 Albahari 的 LinqKit 并给出如下查询时:

return _context.Remunerations.AsExpandable().Include("Employee")

那里没有任何错误。

但结果中不包含员工数据

【问题讨论】:

【参考方案1】:

这是known issue,他们正在努力。当前的development source 有一个扩展方法,它在ExpandableQuery(由AsExpandable() 返回)上执行Include,并将其委托给原始IQueryable

之所以没有出现异常是因为IncludeIQueryable<T>上的扩展方法,而ExpandableQuery也实现了IQueryable。但它没有Include() 的实现,所以Include() 运行,但它什么也不做。

【讨论】:

以上是关于“包含”扩展方法不适用于 LinqKit的主要内容,如果未能解决你的问题,请参考以下文章