0

I want to have a sequence in my database which is not bound to a specific column or table. I found this:

public int GetNextSequenceValue()
{
    var rawQuery = Database.SqlQuery<int>("SELECT NEXT VALUE FOR dbo.TestSequence;");
    var task = rawQuery.SingleAsync();
    int nextVal = task.Result;

    return nextVal;
}

This seems to be exactly what I want, however I'm using code-first and I don't see a way to create the sequence in the first place.

So how do I create a sequence with code-first?

Community
  • 1
  • 1
Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61

1 Answers1

0

Found the solution myself. Just execute this on database creation:

context.Database.ExecuteSqlCommand("CREATE SEQUENCE TestSequence AS int START WITH 1 INCREMENT BY 1;");
Tim Pohlmann
  • 4,140
  • 3
  • 32
  • 61