Reputation: 33
I want to join another table using the query syntax. I am getting the following error:
The LINQ expression 'DbSet() .GroupJoin( inner: DbSet(), outerKeySelector: a => (int?)a.ID, innerKeySelector: b => b.aID, resultSelector: (a, b) => new { // my properties here })' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
My code looks along the lines of:
var q =
from a in As
join b in Bs on a.ID equals b.aID into bs
select new
{
// my properties here
};
I want to join the Bs and access bs
to perform Count()
on it in my list of properpties.
EDIT: Here is an example using LINQPad 7 (default database).
Upvotes: 0
Views: 214
Reputation: 27471
Do not use GroupJoin
(join
which ends with into
) with EF Core, except situation when you need LEFT JOIN. It's translation is strictly limited.
var q =
from a in As
select new
{
...
TotalBCount = Bs.Count(b => b.aID == a.ID)
};
Upvotes: 0