相关疑难解决方法(0)

SelectMany()无法推断类型参数 - 为什么不呢?

我有一张Employee桌子和一张Office桌子.这些通过EmployeeOffices表格以多对多的关系加入.

我想获得一个特定员工(CurrentEmployee)与之关联的所有办公室的列表.

我以为我可以这样做:

foreach (var office in CurrentEmployee.EmployeeOffices.SelectMany(eo => eo.Office))
    ;
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

用于方法"System.Linq.Enumerable.SelectMany(System.Collections.Generic.IEnumerable,System.Func>)"类型参数不能从使用推断.尝试显式指定类型参数.

我知道我可以添加类型参数.但Intellisense认识到它eo.Office属于Office类型.那么为什么编译器不清楚这一点呢?

c# linq entity-framework

25
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

entity-framework ×1

linq ×1