WCF RIA 服务获取插入行的 ID
我正在使用 WCF RIA 服务。我没有使用实体和直接 sql。 就我而言,存储过程和复杂类型可以完成所有工作。所以我遇到了这样的问题: 当我使用存储过程插入一行时,无法自动从数据库更新其 ID。如果使用实体和直接 sql,一切都会顺利。 这是我的存储过程:
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
insert into Product
(
[Name]
,[Note] )
values
(
@Name,
@Note
)
select SCOPE_IDENTITY() as ID
END
解决这个问题的唯一方法是在插入后再次重新加载所有数据。我认为加载所有数据不是一个好主意,因为只有一行必须更新。第二种方法是编写更多代码以从 SQL Server 手动获取新 id,但我相信一定有更好的方法。
I am using WCF RIA Services. I am not using entities and direct sql's.
In my case stored procedures and complex types do all work. So I've faced with such a problem:
when i use store procedure to insert a row,there is no way to automatically update its ID from the database. In case of using entity and direct sql everything goes well.
Here is my stored procedure:
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
insert into Product
(
[Name]
,[Note] )
values
(
@Name,
@Note
)
select SCOPE_IDENTITY() as ID
END
The only way to solve this -is to reload all the data againg after the insert.I think it is not good idea to load all the data, when only the one row must be updated.Second approach is to write some more code to get the new id manually from the SQL Server, but i believe there must be a better approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论