开发者

Linq left joining with non trivial condition

开发者 https://www.devze.com 2022-12-23 13:12 出处:网络
This is fine, it produces a left join var q = from c in categories join p in products on c equals p.Category into开发者_运维问答 ps

This is fine, it produces a left join

var q =
    from c in categories
    join p in products 
    on c equals p.Category into开发者_运维问答 ps
    from p in ps.DefaultIfEmpty()
    select new { Category = c, ProductName = p == null ? "(No products)" : p.ProductName };

But what about if I wanted to do something like this:

...
on p.date between c.startdate and c.enddate
...


var q =
    from c in categories
    join p in products 
    on c equals p.Category into ps
    from p in ps.DefaultIfEmpty()
    where p.date >= c.startdate && p.date <= c.enddate
    select new { Category = c, ProductName = p == null ? "(No products)" : p.ProductName };
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号