Stupid Linq Tricks Record Rollup

I’ve been in these situations too many times where I’ve had to receive a logical document and the "text" has been split across multiple items in a list. Most of the time it occurs with databases but I’ve had to do the same thing with B2B integrations with Xml too.

Before Linq I’d end up with the prototypical foreach code but this last time I need to (re)solve such a problem Linq had since been born.

Here is an example:

Big deal. What if you have a set of data that has multiple comments

Here are the static helper methods I used to kruft up some sample data if you would like to play around with these queries

I do realized that ORM and other database queries have the ability to do these aggregates for you. I was merely trying to point out some Linq tricks for those situations where you are dealing with objects and might not be in a data access situation.

File under:
blog comments powered by Disqus