开发者

Linq left joining with non trivial condition

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜