Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

EF Core manual SQL Server sequence value

Test

Minimal integration test showing how to obtain a SQL Server sequence value with EF Core 10 before inserting an entity. The test starts a real SQL Server 2025 container with Testcontainers, creates the sequence, reads its next value, inserts the entity, and verifies the stored row.

The working query deliberately materializes before calling Single():

var values = await db.Database
    .SqlQuery<long>($"SELECT NEXT VALUE FOR [Schema].[Custom Value]")
    .ToListAsync();
var nextValue = values.Single();

Calling SingleAsync() directly is not valid for this SQL. EF Core composes it as a derived table, but SQL Server does not allow NEXT VALUE FOR in a derived table. ToListAsync() executes the raw SQL without that composition; Single() then checks the cardinality in memory.

Prerequisites:

  • .NET 10 SDK
  • Docker

Run the example:

dotnet test EfNextValue.slnx

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages