If I'm projecting with linq and not using a range variable what is the proper syntax?

Posted by itchi on Stack Overflow See other posts from Stack Overflow or by itchi
Published on 2010-05-19T16:37:22Z Indexed on 2010/05/19 16:40 UTC
Read the original article Hit count: 149

Filed under:
|
|
|

I have a query that sums and aggregates alot of data something like this:

var anonType = from x in collection
               let value = collection.Where(c=>c.Code == "A")
               select new { sum = value.Sum(v=>v.Amount) };

I find it really weird that I have to declare the range variable x, especially if I'm not using it. So, am I doing something wrong or is there a different format I should be following? Also, keep in mind that anonType has about 15 different properties that are all types of aggregates (sums,counts, etc). So I couldn't do something like:

int x = collection.Where(c=>c.Code == "A").Sum(v=>v.Amount);

© Stack Overflow or respective owner

Related posts about c#3.5

Related posts about LINQ