How to get the next Sequence number in Sql Server

2019-04-05 18:26发布

问题:

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

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

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

回答1:

I got it working using SqlQuery like so..

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