Today I needed to add an special field to my LINQ query. A kind of Row Number column. Actually it was not a row number nor was it a column since LINQ deals with objects, but since it was used for presenting data in a tabular way, I see no other name that fits the description.
So, I needed a data displayed in a following format:
| Lp. | Name |
| 1 | Murray N. Rothbard |
| 2 | Hans-Hermann Hoppe |
| 3 | Ludwig von Mises |
First column had to be generated somehow. Using LINQ. I made few quick searches on google, but whith no success, so I came out with my own solution:
int i = 1;
return from author in DataContext.Authors
select new Author() { Lp = i++, Name = author.Name };
So very simple. Isn't it?