“SelectMany”调用中的类型推断失败

时间:2022-02-17 17:04:13

I have this LINQ query:

我有这个LINQ查询:

        var businessAffiliates = from b in context.Businesses
                                 from ba in b.BusinessOfficers
                                 from p in ba.Person                                     
                                 select b;

but I am getting this error:

但是我收到了这个错误:

An expression of type 'myproj.Models.Person' is not allowed in a subsequent from clause in a query expression with source type 'System.Linq.IQueryable'. Type inference failed in the call to 'SelectMany'.

在源类型为“System.Linq.IQueryable”的查询表达式中的后续from子句中不允许使用“myproj.Models.Person”类型的表达式。调用“SelectMany”时类型推断失败。

1 个解决方案

#1


23  

It looks like ba.Person it a single object, but the from clause expects a sequence of objects. if you replace that line with let p = ba.Person then it would work. But i wonder why you need those additional from clauses.

它看起来像ba.Person它是一个单个对象,但from子句需要一系列对象。如果你用let p = ba.Person替换那一行那么它会起作用。但我想知道为什么你需要那些额外的条款。

#1


23  

It looks like ba.Person it a single object, but the from clause expects a sequence of objects. if you replace that line with let p = ba.Person then it would work. But i wonder why you need those additional from clauses.

它看起来像ba.Person它是一个单个对象,但from子句需要一系列对象。如果你用let p = ba.Person替换那一行那么它会起作用。但我想知道为什么你需要那些额外的条款。