Prevent duplicate records with seed

Prevent duplicate records when you use seed method in migration. Originally in Migrations/Configuration.cs we can use: context.People.AddOrUpdate( p => p.FullName, new Person { FullName = “Andrew Peters” }, new Person { FullName = “Brice Lambson” }, new Person { FullName = “Rowan Miller” } ); But when we configure adding record (like sample above) every […]

Some commands: Rollback migration

1.In Package Manager Console command Get-migrations return listing with migration names that you made: Get-Migrations 2. Update db for earlier state: Update-Database –TargetMigration: <name-from-listing-above> 3. Delete file with incorrect migration from your migrations folder in Solution Explorer. 4. Create new correct migration and update db.

Some commands: Enable Database Migrations

If you want to apply database migrations in your project just type in NuGat Console those command: enable-migrations After every change of structure in your database model need to called at migration command with your custom migration name: add-migration <name-of-change> Now it’s time to database update command: update-database and for the end – if something went […]