Savechanges returns the latest insert id to asp mvc ()

asp.net asp.net-mvc-3 entity-framework linq sql

Question

im using poco code first . how do i get the last insert after savechanges() ?

thanks

1
10
11/22/2011 6:59:05 PM

Popular Answer

I resolve that problem in such way:

with Max() - you can get last id from table

db.Products.Add(product);
db.SaveChanges();
int lastProductId = db.Products.Max(item => item.ProductId);

ProductId is Key() and increment

15
3/28/2012 2:38:11 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow