开发者

Scope_Identity() in Entity Framework

开发者 https://www.devze.com 2023-02-25 00:46 出处:网络
What is the equal code in EntityFramework to this sql code? 开发者_Go百科select Scope_Identity() I want to get the id of the last record that i have inserted to database in EF.You must ensure that

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

开发者_Go百科
select Scope_Identity()

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


You must ensure 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 the 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消