【问题标题】:"Include" extension method does not work with LinqKit“包含”扩展方法不适用于 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")

那里没有任何错误。

但结果中不包含员工数据

【问题讨论】:

    标签: c# linq-to-entities entity-framework-6 linqkit


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 1970-01-01
      • 2019-04-23
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2021-06-12
      相关资源
      最近更新 更多