Luffy Ding Luffy Ding - 1 month ago 5x
C# Question

How to initialize System.Data.Entity.Migrations.DbMigrationsConfiguration.Seed()

How to make AddOrUpdate() generating update t-sql?

How to make AddOrUpdate() generating t-sql sent to sql server in sequence?

How to create multiple columns 'reference' index in EF6?


This is to gather all the solutions of pitfall I encountered on initializing System.Data.Entity.Migrations.DbMigrationsConfiguration.Seed().

I am T-SQL master, but I'm not EF master due to I always on the MS SQL side.

I found DbContext.AddOrUpdate(new instance(){}) didn't generate the update T-sql, and throw exception when EF encountered inserting the repeat row error in sql server.

Here is the solution gave by roelant-m:

migrationdbsett addorupdate trouble

When I solved the AddOrUpdate(new Instance(){}) inserting same row problem, I encountered the EF optimizing problem, yeah, he is so smart that optimize all the AddOrUpdate( new instance()) in method Seed(). and then he throw exceptions.

Due to the Initializing database must be in sequence (some table has referenced the other tables.)

Here is the solution gave by endi zhupani:

how to make the addorupdate run in order in dbmigrationconfiguration derived

When I solved the initializing AddOrUpdate(new Instance(){}) in sequence, I encountered the multiple column 'references' index, some element of the index are navigation property.

Here is solution gave by sampath:

how to create multi columns reference index join index in csharp model