实体框架4获得主键ID为插入的记录 [英] Entity Framework 4 getting primary key ID for inserted record

查看:249
本文介绍了实体框架4获得主键ID为插入的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是实体框架插入一行到我的SQL数据库。如果我使用一个存储过程,然后我就可以返回主键我已经插入的记录。

我能够做返回的PK使用实体框架的最后我的最后一个记录插入?

解决方案

在已插入它应该被更新,这样一个映射到数据库中的主键属性具有新的PK值的实体。

I am using the Entity Framework for inserting a row into my sql database. If I was to be using a stored procedure then I would be able to return the primary key for the record which I had inserted.

Am I able to do return the PK for the last my last record inserted using the Entity Framework?

解决方案

After you have inserted the entity it should have been updated so that the property that maps to the primary key in the database has the new PK value.

这篇关于实体框架4获得主键ID为插入的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆