I'm using LINQKit in a query with LeftJoin in it :
return _context.User
.LeftJoin(
_context.JournalAcces,
u => u.Login,
j => j.LoginUtilisateur,
(u, j) => new { U = u, J = j })
.AsExpandable()
.Select(x => new User
{
Login = x.U.Login,
Date = x.J.Date,
IsUsed = IsUsed().Invoke(x.U),
})
.ToList();
I get this error message : the LINQ expression could not be translated
But if I replace LeftJoin
by Join
, it works.
I also tried adding LINQKit configuration on DbContextOptions level :
builder
.UseNpgsql(connectionString)
.WithExpressionExpanding();
and deleted the .AsExpandable() from the query, but I got the same error :
return _context.User
.LeftJoin(
_context.JournalAcces,
u => u.Login,
j => j.LoginUtilisateur,
(u, j) => new { U = u, J = j })
.Select(x => new User
{
Login = x.U.Login,
Date = x.J.Date,
IsUsed = IsUsed().Invoke(x.U),
})
.ToList();
Is this a bug in LINQKit or a limitation ? because I couldn't find any reference for it in the documentation nor in the open issues.
For reference, IsUsed is defined like this :
public static Expression<Func<User, bool>> IsUsed()
{
return x => x.Employement == "Employed";
}