I'd suggest to check out this thread:
c# - How to generate and auto increment Id with Entity Framework - Stack Overflow[
^] and this:
Auto Increment (Identity) does not work in Entity Framework | The ASP.NET Forums[
^]
Conclusion: Autoincrement serial number handle by yourself is very poor idea for several reasons! This should be done on database (entity) level.
But, if you would like to know, how to create value which will be increasing inside a Linq query, check this:
var result = Enumerable.Range(5,20)
.Select((x,y) => new
{
index = y+1,
value = x
})
.ToList();
int index = 1;
var result2 = (from a in Enumerable.Range(5,20)
select new
{
index = index++,
value = a
})
.ToList();
Both produce the same result:
index value
1 5
2 6
3 7
...
20 24