开发者

Updating values and returning updated values in Entity framework

开发者 https://www.devze.com 2023-03-23 14:54 出处:网络
i have a table which i use to implement a开发者_StackOverflow中文版 sequence in Sql Server 2008. The sequence table has just 1 column which is an integer.

i have a table which i use to implement a开发者_StackOverflow中文版 sequence in Sql Server 2008. The sequence table has just 1 column which is an integer.

I want to know if i can do something like this

update dbo.MySequence set val=val+1 output inserted.val

and return value without using stored procedures in Entity Framework.

Thanks.


Why to avoid stored procedures? Using stored procedures is part of using EF. You don't have to create stored procedure but you still have to call direct SQL (for example with context.ExecuteStoreQuery). For example on MS SQL you can use:

DECLARE @val INT
UPDATE dbo.MySequence SET @val = val = val + 1
SELECT @val 

But it is better to have sequences named (with additional column).

0

精彩评论

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