如何使用实体框架在 Sql Server Express 中获取下一个序列号? [英] How to get the next Sequence number in Sql Server Express using Entity Framework?

查看:25
本文介绍了如何使用实体框架在 Sql Server Express 中获取下一个序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在 Sql Server 2012(包括 SQL Server Express 2012)具有 SEQUENCE 功能,就像 Oracle 所解释的 这里此处这里.

Now that Sql Server 2012 (including SQL Server Express 2012) has SEQUENCE feature just like Oracle as explained here, here, and here.

我可以像这样得到下一个sequenceSELECT NEXT VALUE FOR SeqName

I can get the next sequence like so, SELECT NEXT VALUE FOR SeqName

但是我如何使用 Entity Framework 5 从我的代码中做到这一点?

But how do I do that from my code using Entity Framework 5?

推荐答案

我像这样使用 SqlQuery 让它工作..

I got it working using SqlQuery like so..

int sequence = context.Database.SqlQuery<int>("SELECT NEXT VALUE FOR MySequenceName").FirstOrDefault();

这篇关于如何使用实体框架在 Sql Server Express 中获取下一个序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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