Support ForNpgsqlUseIdentityAlwaysColumns with HasData
See original GitHub issueCurrently Entity Framework Core’s data seeding feature HasData
does not support ForNpgsqlUseIdentityAlwaysColumns
, because GENERATED ALWAYS AS IDENTITY
does not allow inserting values in the identity column if OVERRIDING SYSTEM VALUE
is not specified in the INSERT
clause.
This could be supported by adding InsertDataOperation
hook to NpgsqlMigrationsSqlGenerator
. For inspiration, here’s the SqlServerMigrationsSqlGenerator
implementation using SET IDENTITY_INSERT
.
See also the earlier discussion.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:17 (12 by maintainers)
Top Results From Across the Web
Data Points - Deep Dive into EF Core HasData Seeding
I wrote about this new support in the April 2018 Data Points column (msdn.com/magazine/mt846463). Because an owned type is specific to the entity...
Read more >Data Seeding - EF Core
When a migration is added the changes to the data specified with HasData are transformed to calls to InsertData() , UpdateData() , and ......
Read more >EFcore with IdentityDbContext and hasData seeding ...
After setting the HasData and seeding the DB, created a new migration, it created a new migration where it wanted to drop the...
Read more >The Fluent API HasData Method
The Entity Framework Core Fluent API HasData method is designed to help provide seed data for migrations to the specified entity.
Read more >Seeding Related Entities in EF Core 2.1's HasData()
If you didn't notice, Entity Framework Core 2.1 has a new way to support seeding your databases with a method called HasData.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Done, seeding now works with IDENTITY ALWAYS. However, you still need to use negative values to avoid conflicts.
@Sigvaard that’s right - seed with negative values to make sure seeded values don’t collide with values later generate from the identity sequence.