zzzprojects / System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
https://dynamic-linq.net/
Apache License 2.0
1.57k stars 228 forks source link

How to implement Left outer join with Linq.Dynamic? #419

Open pyramidsbuilder opened 4 years ago

pyramidsbuilder commented 4 years ago

I am trying to get left outer join working with linq dynamic, The ideas I got is that I need to use group join with select many, So, I think I need to translate the following example to linq dynamic but I cannot get the syntax right: please help translating this linq code to Dynamic Linq

db.Categories .GroupJoin(db.Products, Category => Category.CategoryId, Product => Product.CategoryId, (x, y) => new { Category = x, Products = y }) .SelectMany( xy => xy.Products.DefaultIfEmpty(), (x, y) => new { Category = x.Category, Product = y }) .Select(s => new { CategoryName = s.Category.Name, ProductName = s.Product.Name });

Thanks

JonathanMagnan commented 4 years ago

Hello @leaditnet ,

For this kind of question, I recommend you to use instead Stack Overflow: https://stackoverflow.com/search?q=%5Bdynamic-linq%5Dleft+join&mixed=0

From one of these questions, I discovered this library: https://github.com/SikeyMael/LinqHelper which may help you to achieve what you want.