EF Core Keys Get IDENTITY, Not Sequences? Fix with UseKeySequences
If your EF Core model targets SQL Server, you expect sequence-generated keys, and you find IDENTITY instead, you’re seeing SQL Server’s documented default. If you want sequence-generated keys on SQL Server, pick UseKeySequences and call it on the ModelBuilder in OnModelCreating. As of November 2026, per the EF Core API docs, it takes an optional nameSuffix (appended to the table name) and an optional schema (the sequence’s schema).
modelBuilder.UseKeySequences(nameSuffix: "_1sq", schema: "app_owner");
One wording detail matters. You probably want a sequence per table, but the docs say “a sequence per hierarchy,” so confirm what you actually get in a migration. That check is the part worth your attention, and it’s covered at the end.
Why your keys are IDENTITY
There’s no error to paste. The symptom is a model that never asks for sequences. This is a reconstructed example, not captured output:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// no UseKeySequences call, no sequence configuration
}
On SQL Server, the documented default for OnAdd keys is an IDENTITY column. UseIdentityColumns is the default when you target SQL Server, so a model with no key strategy call behaves as if you’d called it. No sequence setup means the database never gets a sequence. The model did exactly what it was told, which was nothing.
Three model-level methods choose the strategy:
| Method | Role for OnAdd keys |
|---|---|
UseIdentityColumns |
IDENTITY columns. |
UseHiLo |
Hi-lo values drawn from a database sequence. |
UseKeySequences |
A sequence per hierarchy, set up on ModelBuilder. |
Treat these as alternatives. The material I have describes each one as a model-level setting for OnAdd keys. It doesn’t say what happens if you call UseHiLo and UseKeySequences in the same model, so I won’t guess. Pick one.
Turning on key sequences
1. Call UseKeySequences in OnModelCreating
UseKeySequences is an extension on ModelBuilder. Call it once in OnModelCreating, and key values marked OnAdd come from sequences instead of IDENTITY.
modelBuilder.UseKeySequences();
Again, the listing says “a sequence per hierarchy,” not strictly one per table. Check the generated sequences against your model.
2. Pass nameSuffix to control sequence names
nameSuffix is the text appended to the table name for each sequence EF Core creates automatically. The default value when you omit it isn’t in the source I have, so I won’t state it.
modelBuilder.UseKeySequences(nameSuffix: "_1sq");
With a table named app_person, my reading is that this yields app_person_1sq. That’s an inference from the parameter description, not verified output.
This is the step where existing databases get stuck. nameSuffix is a single string appended to every table name. If your database already has person_seq next to order_id_gen, one suffix can’t produce both names, and the suffix and schema settings won’t line up with what’s there on their own. The material I have doesn’t confirm a per-entity way to point keys at existing sequences or to map the odd ones by hand, so check the EF Core docs for that.
Renaming the existing sequences to fit the suffix is the other option, but it can break dependent objects such as default constraints or stored procedures. If you consider it, do it on a restored copy first and check what depends on each sequence.
3. Pass schema to put the sequences in a specific schema
schema sets the schema of the sequence. Use it when your sequences should live outside the default schema. If they don’t need to, leave it off, because that’s one less name to check in the migration.

modelBuilder.UseKeySequences(nameSuffix: "_1sq", schema: "app_owner");
Combining this with step 2, the target name would be app_owner.app_person_1sq. That also follows from the two parameter descriptions and isn’t confirmed by a generated migration.
Don’t read schema as moving your tables. Per the API listing, it sets the schema of the sequence and says nothing about the tables. If your tables sit in app_owner too, open the generated migration and confirm where each sequence and table ends up.
4. Chain further calls if you need them
UseKeySequences returns the same builder instance, so you can chain calls. That’s all the listing says. It names no specific method to follow it with, so I won’t show a chained example I can’t back up.
Check the migration before you ship
The source I worked from is an API member listing. It doesn’t show migration output, generated SQL, sequence start values or cache behavior, which is why every name above comes with a caveat. Verify it yourself:
- Add a migration after the change.
- Open the generated migration file and look for the sequences and the key column definitions.
- Confirm the sequence names match table name plus
nameSuffix, in the schema you passed.
As of November 2026, I couldn’t confirm which EF Core version introduced UseKeySequences. Check the API docs for the exact EF Core version your project uses before you build on it. The API documentation also points to “Modeling entity types and relationships” and “Accessing SQL Server and Azure SQL databases with EF Core.” I didn’t check either page for UseKeySequences specifics.
Before you apply that migration to a populated IDENTITY database, know that the source says nothing about converting existing IDENTITY columns to sequences or about what happens to current rows. So restore a copy of the database, run the migration there, and read the SQL it produces before you touch production.
Sources
This article was created using generative AI based on publicly available sources.