因此,我分别以ID的1,2,3和4播种了一些Identity Server用户。在运行应用程序后尝试插入新用户后,我必须“尝试”插入4次,然后将ID设置为5,然后我才能开始无误地插入。
我曾尝试寻找答案,但很短。问题-通过种子植入后使用ModelBuilder或查询数据库,这种可行的低谷代码优先方法吗?
此外,我在Asp Net Core应用程序中以代码优先方法使用PostgreSQL数据库。
编辑:另外,这是所有ID列约束,它们表明它是一个标识列。
我发现比在数据库条目上设置负值更正确的解决方法。
// Set starting value to start after seeded data count. Must be done
// to any entity, that can be added to from application logic.
builder.Entity<SomeTable>()
.Property(b => b.YourIdProperty)
.HasIdentityOptions(startValue: seededDataCount + 1);
这是针对postgreSQL的,但对于其他实现应该确实类似。