I am writing a .NET Framework WPF application and I use Entity Framework. At first I installed the EF Core package and when doing my first add-migration I received the famous error
Unable to create an object of type 'DbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
However, this is not what my question is about. I knew I got it to work sometime before and I noticed that that was when I used EF 6 instead of EF Core. So I uninstalled the EF Core packages and installed EF 6 package instead. And now with EF 6 migrating works just fine, which is great.
But my question is: why IS it working? Even though I did not change my code by adding an IDesignTimeFactory<DbContext> or dependency injection for instantiation of my DbContext class. Yet it still works just by switching back to EF 6. I couldn't find any information on differences between the two (i.e. EF Core and EF 6) that would explain this. So now I'm hoping someone here can enlighten me with their vast knowledge.
For reference, here is my DbContext class:
public class PinboardContext : DbContext
{
public PinboardContext() : base()
{
}
public DbSet<Item> Items { get; set; }
}
My App.xaml.cs class is empty apart from an empty constructor.
Lastly, if that is of importance, I have a connectionString defined in app.config as follows:
<connectionStrings>
<add name="mpcn" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=MyPinboardDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Note that I have already looked at this but it didn't help me answer my question.
using System.Data.Entity;and in EF Core -using Microsoft.EntityFrameworkCore;. The fact that it is working with EF6 means the code never worked with EF Core.