question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support ForNpgsqlUseIdentityAlwaysColumns with HasData

See original GitHub issue

Currently 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
rojicommented, Aug 8, 2018

Done, seeding now works with IDENTITY ALWAYS. However, you still need to use negative values to avoid conflicts.

2reactions
rojicommented, Dec 14, 2018

@Sigvaard that’s right - seed with negative values to make sure seeded values don’t collide with values later generate from the identity sequence.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found