Savechanges returns the latest insert id to asp mvc ()

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

Question

I'm starting with poco coding. What was the most recent insert made after savechanges()?

thanks

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

Popular Answer

I find a solution to the issue as follows:

You may get the table's last ID using Max().

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

ProductId is incremented by Key().

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