Entity Framework's Scope Identity() method

c# entity-framework

Question

What is the equal code in EntityFramework to this sql code?

select Scope_Identity()

I want to get the id of the last record that i have inserted to database in EF.

1
2
4/13/2011 8:05:59 AM

Accepted Answer

You must unsure that your key property is mapped with StoreGeneratedPattern.Identity (here you can find some more about this setting). This should be used as default when generating model from MS SQL database where the key column is defined with IDENTITY. After that it is enough to call SaveChanges on the context and the key property will be automatically filled for you.

3
5/23/2017 10:27:14 AM


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