EF Core automatic migration

In our way toward migrating an ASP.NET full framework application to ASP.NET Core 2.0 we encountered a significant change in EF Core 2.0 in comparison with EF 6.x.


EF 6.x

In EF 6.x we were tightly relying on automatic migrations in deployment operations. We never created or added a migration to the code-base. Instead we had turned on automatic migration and allowed data loss. So when new versions of the project were deployed on the server, all necessary changes on the database were done behind the scenes automatically.

I know that enabling automatic migration on a production server is not a good idea. But it was a constraint forced by our deployment team.

Entity Framework Core
Entity Framework Core

EF Core

Automatic migration has been removed from EF Core. This feature is not present in EF Core 2.0. There is no plan to add this feature to EF. Microsoft thinks it benefits is less than its drawbacks.

There are 2 methods in EF Core 2.0 related to migration. Database.Migrate() and Database.EnsureCreated(). Neither of them are a complete migration.

Migrate() does not add or create a migration. It only checks if any not-applied migrations exists or not. If yes, then updates the database based on them.

EnsureCreated() creates the database based on the models in the project. But it does not do this in the migration way. Actually no migrations are needed by this method. Disadvantage of this method is that a database created by it, can not be updated in future by any migrations. Indeed this method is added to EF to help people create projects fast in MVP style.


At the end, we decided to not having automatic migrations as EF 6.x. Everyone that creates a model is responsible to create migrations too. And never call EF command in the production server to update the database. Instead call the Migrate() method on each startup to take the database to the latest available migration.

A sample code would be like this:


Sample code inspired from here.

Migrating from Orchard CMS to WordPress

Well, it may be a little strange. Migrating from a more universal CMS like Orchard CMS to a simpler CMS like WordPress is not a job everyone wants to do. There are several tutorials for migrating from WordPress to Orchard CMS but I found few on migrating from Orchard CMS to WordPress. One of guides I found was Ricky Smith's guide.

Orchard CMS is a .Net open source CMS. It has little community in comparison with WordPress. So has fewer themes, plugins and developers. Orchard CMS is also a bit complexer than WordPress. It only install on Windows server while WordPress can be hosted on both Windows and Linux. These were my reasons to migrating from Orchard CMS to WordPress. My website was not very complex, it contained three blogs with likely 500 posts, some 30 pages and a simple data gathering form.

I found that Orchard CMS's original Import/Export module is my best chance. Select Export tab then check “Blog Post” and “Data” options and finally hit “Export” button. A file named export.xml will be downloaded for you.


There are many import plugins for WordPress. One of them that works well is “WP All Import”. With it importing data into WordPress from XML files is easy. First step is uploading XML file into it. Then specify if you are importing data into Posts or Pages. Step 2 is very important. Here you specify what section of XML file contains actual data. By adding filter options you tell the plugin what records must be imported. For me “blogpost” section had all data I needed. I used XPath based filtering mechanism to exclude some unwanted records.


In step 3 you tell “WP All Import” what data field from XML belongs to what data field in WordPress. It is drag and drop. See following picture as a sample. Don't worry for mistakes. The plugin allow to go backward/forward in steps.


Following next steps you will import data from Orchard CMS to WordPress successfully. Notice that in this scenario I haven't imported comments. Enjoy your new CMS!