I have the following SQL , how do I implement this in LINQ (c# please :))
SELECT a.Category, a.Description, a.Item, a.[Value], a.Loading, a.MaxDiscount, MIN(b.EffectiveDate) AS FromDate, a.EffectiveDate AS EndDate, a.SortOrder, a.ID
FROM List a
LEFT OUTER JOIN List b ON a.[Value] = b.[Value] AND a.Category = b.Category AND a.Description = b.Description AND a.Item = b.Item AND a.EffectiveDate < b.EffectiveDate
GROUP BY a.Category, a.Description, a.Item, a.[Value], a.Loading, a.MaxDiscount, a.SortOrder, a.EffectiveDate, a.ID
HAVING (a.Category = 'General') AND (a.Description = 'Cover') AND (a.EffectiveDate <= CONVERT(DATETIME, '2009-04-01 00:00:00', 102)) AND (MIN(b.EffectiveDate) >= CONVERT(DATETIME, '2009-04-01 00:00:00', 102) OR MIN(b.EffectiveDate) IS NULL) AND (a.Item = 'Type')
ORDER BY a.SortOrder
I have the following (using SubSonic Linq)
var query = from a in List.All() join b in List.All()
on new {a.Value,a.Category ,a.Description,a.Item}
equals new {b.Value,b.Category ,b.Description,b.Item} into temp
I have no idea how to add the a.EffectiveDate < b.EffectiveDate at the moment