Sponsor: Using RabbitMQ or Azure Service Bus in your .NET systems? Well, you could just use their SDKs and roll your own serialization, routing, outbox, retries, and telemetry. I mean, seriously, how hard could it be?

Side by Side
In theory, you should be able to run EF 6 along side EF Core. They are completely different packages, assemblies and namespaces. However in practice, that wasn’t possible in my situation.MySql.Data
This project in particular that I was porting was using MySQL. The official provider to use with EF6 is MySql.Data.Entity. This package has a dependency on the ADO.NET driver MySql.Data. EFCore has an official provider, MySql.Data.EntityFrameworkCore. It also has a dependency on MySql.Data, but a newer version. A wonderful diamond dependency. Full roadblock.Porting
I ended up removing all of the EF6 packages and references and installed the latest EF Core package and MySQL provider. Here are some of the changes that I needed to make.DbContext
My only significant change was adding a OnConfiguring override to specify which provider to use and the connection. The extension methodUseMySql
is from the MySql provider, which is being passed the connection.
SqlQuery<T>
This is no longer available and you must now use the FromSql method to perform raw SQL queries.FromSql
is available on all the DbSet<T>
in your DbContext
Namespaces
Using statements were more of a pain then anything. Really a matter of removing any using statements toSystem.Data.Entity
and replacing with relevant Microsoft.EntityFrameworkCore
Composite Key
You can no longer use data annotations to declare composite keys. This must be done through the fluent API.Lazy Loading
As of EF Core 2, lazy loading is not supported. Luckily I’ve never been a fan of lazy loading and generally find it causes more harm then good. If you are using lazy loading, there’s a package EntityFramework.LazyLoading that enables the ability with some minor changes to yourDbContext