I am building an ASP.NET Core 1.1.0 application that needs to access an existing MySQL database using Entity Framework Core, which I'm building in Visual Studio 2015 with all the latest updates. I started using the "official" MySQL provider (MySql.Data.EntityFrameworkCore), but have the same problem with the Pomelo prvider (Pomelo.EntityFrameworkCore.MySql).
The context object injected into my Home controller has all kinds of NotImplemented exceptions, as you can see in the image. Members is one of my DBSet collections, using the Member POCO. (By the way, I'm not planning on using migrations, so that's not a factor.) This is the state of the context object as soon as it's injected into the controller, before I even try to access data.
The full detail of a typical message is:
((Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure)this.db.Members).Instance' threw an exception of type 'System.NotImplementedException
I don't think there's anything very interesting in my project.json file, but the relevant lines are:
"Pomelo.EntityFrameworkCore.MySql": "1.1.0",
"Pomelo.EntityFrameworkCore.MySql.Design": "1.1.0"
In Startup.cs in the ConfigureServices method, I have these statements:
string connectionString = Configuration.GetConnectionString("ManageRCNConnection");
services.AddDbContext<MembersContext>(options => options.UseMySql(connectionString));
Things are pretty simple at this point.
So far, my Google-foo has let me down trying to figure out what's wrong.
Can anyone give me a clue about what the problem is?
Thanks!
Update: If I ignore the errors in the constructure as @Tseng suggests, I get errors the first time I try to get an entity from the database.
Here is the code for my MembersContext. I've removed a few of the properties, but they are just more DbSet collections.
public class MembersContext : DbContext
{
public MembersContext(DbContextOptions<MembersContext> options) : base(options)
{ }
public DbSet<Member> Members { get; set; }
public DbSet<FamilyMember> FamilyMembers { get; set; }
public DbSet<Membership> Memberships { get; set; }
...
}
I'm not using a context factory, might that be the problem?
context.Database.EnsureCreated()
(orcontext.Database.Migrate()
if you use migration) or its async variants during startup? Without it, the database is never created