SapientGuardian / mysql-connector-net-netstandard

ADO.NET driver for MySQL targeted against netstandard 1.3
GNU General Public License v2.0
46 stars 15 forks source link

Provide Example for configuring DbContext for EF7 Models #23

Closed caleblloyd closed 8 years ago

caleblloyd commented 8 years ago

For my EF7 models, I am currently using:

using Microsoft.EntityFrameworkCore;
public class AppDb : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite("Filename=/root/test.db");
    }
}

Could you provide an example of how I could configure the models to use this MySQL connector instead? Or is EF7 support still in the works?

SapientGuardian commented 8 years ago

Hi @caleblloyd. I don't believe there's any way to use this library along with EF7, at least not without writing some sort of adapter code. I'm not a huge fan of EF, and wasn't planning on creating a MySql implementation for it; I'm not sure if anyone else is either. I don't know all of the details, but I suspect that EF7 support could be done in an independent library that references this one. That said, if some changes needed to be made in this project to facilitate that, I'd be open to a PR.

If you're not dead set on EF, I believe some folks are successfully using this library with Dapper.

caleblloyd commented 8 years ago

Thanks for getting back to me on it this. Microsoft's official statement is "We are working with the MySQL team to make a MySQL provider available. Please direct any questions about this provider, including the release timeline, to the MySQL Project." from https://ef.readthedocs.io/en/latest/providers/mysql/index.html

The MySQL team has been pretty quiet about an actual date, and I found that you had brought their code up to .NET Core standards from a link on the MySQL form. Hopefully they backport your fixes and get the EF7 adapter published soon! Thanks.

SapientGuardian commented 8 years ago

It is now possible to use this library with EF through the provider library at https://github.com/SapientGuardian/SapientGuardian.EntityFrameworkCore.MySql. Here's a sample project: https://github.com/SapientGuardian/AspNet5MultipleProject

caleblloyd commented 8 years ago

@SapientGuardian this is great, I installed the NuGet package, switched to MySQL, and regenerated my EF Migrations. Everything migrated up successfully! I'll test putting data into the DB tomorrow and open any issues I find against the appropriate repo.

You should pull request Entity Framework docs at http://ef.readthedocs.io/en/latest/providers/mysql/index.html and add this implementation. It's the first open source MySQL Connector in EF7!

Thank you and @how02 for the hard work on getting this in EF Core!