2010-03-15 62 views
0

,这是好的,它会产生一个左连接的LINQ留下了不平凡的条件加入

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 }; 

可是你知道,如果我想要做这样的事情:

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

回答

1
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

除了我对原始条款不感兴趣。我用1等于1代替它。但是这不会太麻烦吗? – Martin 2010-03-15 14:56:39