LeftJoin with Linq fluent syntax?
See original GitHub issueAll the Join examples on the wiki use linq’s query syntax (eg: from u in Users select u.Name
), but I’m used to the fluent/method syntax (eg: Users.Select(u => u.Name)
).
Why can’t I do something like the following:
db.Users.LeftJoin(db.Posts, u => u.Id, p => p.UserId);
Something like the Join
that already exists in System.Linq.Queryable
but would generate a Left Join instead of an Inner Join.
The current implementation of LeftJoin only accepts a Func<T, bool>
and I have no idea how to make that work in fluent syntax.
Note: LoadWith
isn’t working properly for me, it still generates “n+1” queries instead of a single join query (even though I’ve seen old closed issues here saying that it’s implemented).
Environment details
linq2db version: 1.10.2 (Core) Database Server: MySQL 5.7.21 Database Provider: MySql.Data 6.10.6 Operating system: Windows 10 Pro Framework version: .NET Core 2.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (7 by maintainers)
fixed by #1088
@hassanselim0, at first we are thinking how to write linq experssion to be closer to sql. So linq queries are supported by default. With fluent syntax there are many possibilities to write expression that can not be converted to real SQL. I’ll check maybe we can support this fluent syntax without additional superfluous calculations.