Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

incrementing an ID column

$
0
0

Whenever I'm adding a new object from the front end, the id = 0.  In the WebApi layer, I'm trying to find the max ID that exists in the list of events and then assign the next ID to the new objects.  The code below doesn't increment the ID correctly

List<Event> events = eventVal.Where(e => e != null).ToList();
int eventMaxID = events.Max(e => e.id);

events.Select(e => e.id == 0)
      .Select((e, ixc) => new { id = eventMaxID + 1, Iter = eventMaxID + 1 })
      .ToList();

I'm not sure how to use the second parameter for the Select method.

Any help would be appreciated! Thanks.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>