System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

How to implement Left outer join with Linq.Dynamic?

Open pyramidsbuilder opened this issue 5 years ago • 1 comments

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

pyramidsbuilder avatar Sep 12 '20 10:09 pyramidsbuilder

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.

JonathanMagnan avatar Sep 13 '20 02:09 JonathanMagnan