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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 withIDENTITY. After that it is enough to callSaveChangeson the context and the key property will be automatically filled for you.