Tutorial by Examples

To enable Code First Migrations in entity framework, use the command Enable-Migrations on the Package Manager Console. You need to have a valid DbContext implementation containing your database objects managed by EF. In this example the database context will contain to objects BlogPost and Auth...
After you've enabled migrations (please refer to this example) you are now able to create your first migration containing an initial creation of all database tables, indexes and connections. A migration can be created by using the command Add-Migration <migration-name> This command will c...
After enabling and creating migrations there might be a need to initially fill or migrate data in your database. There are several possibilities but for simple migrations you can use the method 'Seed()' in the file Configuration created after calling enable-migrations. The Seed() function retrieves...
For example: You are going to migrate an existing column from non-required to required. In this case you might need to fill some default values in your migration for rows where the altered fields are actually NULL. In case the default value is simple (e.g. "0") you might use a default or d...
Applications running in non-development environments often require database updates. After using the Add-Migration command to create your database patches there's the need to run the updates on other environments, and then the test environment as well. Challenges commonly faced are: no Visual S...
Create a console application. Install EntityFramework nuget package by running Install-Package EntityFramework in "Package Manager Console" Add your connection string in app.config file , It's important to include providerName="System.Data.SqlClient" in your connection. Cre...

Page 1 of 1