268

Can't find anything relevant about Entity Framework/MySQL on Google so I'm hoping someone knows about it.

2
  • 8
    frankly speaking, mysql support for LINQ is crap! I am banging my head on minor issues for last one week :| ...
    – effkay
    Dec 25, 2009 at 7:04
  • 1
    did u use dblinq code.google.com/p/dblinq2007?
    – Sharique
    Jul 14, 2010 at 7:34

10 Answers 10

192

It's been released - Get the MySQL connector for .Net v6.5 - this has support for [Entity Framework]

I was waiting for this the whole time, although the support is basic, works for most basic scenarios of db interaction. It also has basic Visual Studio integration.

UPDATE http://dev.mysql.com/downloads/connector/net/ Starting with version 6.7, Connector/Net will no longer include the MySQL for Visual Studio integration. That functionality is now available in a separate product called MySQL for Visual Studio available using the MySQL Installer for Windows (see http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html).

10
  • 4
    I thought I'd mention that the latest version is available here (current 6.2.2): mysql.com/downloads/connector/net
    – Brett Ryan
    Mar 10, 2010 at 14:34
  • 3
    Does this support EF4 and VS2010? I installed the connector and tried to add a new connection in VS2010 but MySQL does not show up in the list of providers May 13, 2010 at 7:07
  • 1
    I'm curious about MySQL, EF4 and VS2010. Jun 29, 2010 at 20:43
  • 1
    It should if you have the latest connector. I just moved my product to .NET4 specifically because of MySQL Entity support. The tools and everything work okay, but the big issue is the underlying support it provides for actual querying. There's quite a few problems with lamba expressions that you don't run into with MSSQL Aug 18, 2011 at 3:30
  • 1
    Ofcourse, there are new versions coming out. Now supporting EF5, version 6.7.4: dev.mysql.com/downloads/connector/net/#downloads Also, Since this version, the VS plugin with MySQL server and other tools included is bundled in one package: dev.mysql.com/tech-resources/articles/…
    – Nullius
    Jul 19, 2013 at 13:32
21

Check out my post on this subject.

http://pattersonc.com/blog/index.php/2009/04/01/using-mysql-with-entity-framework-and-aspnet-mvc-–-part-i/

4
  • I fixed the encoding of that link - users can now click right through rather than have to copy/paste or select/goto Apr 18, 2011 at 13:58
  • 7
    Link doesn't work
    – MüllerDK
    Nov 17, 2011 at 8:20
  • 2
    You can get to the articles with this link: pattersonc.com/blog/2009/04
    – Andy White
    Jan 17, 2012 at 19:54
  • Is using MYSQL with EF got any better or there are still issues?if SQL server is preferable can anyone pinpoint exactly why SQL server is preferable just because its the same vendor Microsoft? Feb 18, 2017 at 2:45
10

MySQL is hosting a webinar about EF in a few days... Look here: http://www.mysql.com/news-and-events/web-seminars/display-204.html

edit: That webinar is now at http://www.mysql.com/news-and-events/on-demand-webinars/display-od-204.html

1
7

This isn't about MS and what they want. They have created an *open system for others to plug-in 'providers' - postgres and sqlite have it - mysql is just laggin... but, good news for those interested, i too was looking for this and found that the MySql Connector/Net 6.0 will have it... you can check it out here:

http://www.upfromthesky.com/blog/post/2009/03/24/MySql-Supports-the-Entity-Framework.aspx

1
  • 1
    I wonder what "initial" means when they said "Initial Entity Framework support".
    – vintana
    Mar 26, 2009 at 13:36
5

You would need a mapping provider for MySQL. That is an extra thing the Entity Framework needs to make the magic happen. This blog talks about other mapping providers besides the one Microsoft is supplying. I haven't found any mentionings of MySQL.

1
  • Yeah, you're right. I was hoping there's something ready right now.
    – vintana
    Sep 16, 2008 at 20:58
2

Vintana,

Od course there's something ready now. http://www.devart.com/products.html - it's commercial although (you have a 30days trial IIRC). They make a living writing providers, so I guess it should be fast and stable. I know really big companies using their Oracle provider instead of Orace and MS ones.

1
  • Thank you for your response. @Vintana, you can find more information about dotConnect for MySQL and its advantages here devart.com/dotconnect/mysql. To improve your work with Entity Framework entities we provide an advanced tool for visual model creation - Entity Developer devart.com/entitydeveloper.
    – Devart
    Dec 7, 2010 at 16:01
1

Be careful using connector .net, Connector 6.6.5 have a bug, it is not working for inserting tinyint values as identity, for example:

create table person(
    Id tinyint unsigned primary key auto_increment,
    Name varchar(30)
);

if you try to insert an object like this:

Person p;
p = new Person();
p.Name = 'Oware'
context.Person.Add(p);
context.SaveChanges();

You will get a Null Reference Exception:

Referencia a objeto no establecida como instancia de un objeto.:
   en MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
   en MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
   en MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
   en MySql.Data.Entity.SqlFragment.ToString()
   en MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
   en MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   en System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   en System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
   en System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
   en System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
   en System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
   en System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
   en System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
   en System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
   en System.Data.Entity.Internal.InternalContext.SaveChanges()
   en System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   en System.Data.Entity.DbContext.SaveChanges()

Until now I haven't found a solution, I had to change my tinyint identity to unsigned int identity, this solved the problem but this is not the right solution.

If you use an older version of Connector.net (I used 6.4.4) you won't have this problem.

If someone knows about the solution, please contact me.

Cheers!

Oware

3
  • The error is thrown because p is null. You have to create a new empty instance of the object first. I.e. Person p = new Person(); not Person p; So: Person p = new Person(){Name = "Oware"}; context.Person.Add(p); context.SaveChanges();
    – Dave
    Oct 10, 2013 at 14:55
  • sorry I forgot to add the new line, even if I add the new line, the error stills appearing
    – oware
    Oct 11, 2013 at 15:22
  • The bug is fixed in version 6.8.2. bugs.mysql.com/bug.php?id=70888 Connector/Net 6.8.3 is released. dev.mysql.com/downloads/connector/net Jan 10, 2014 at 13:20
1

You might also look at https://www.devart.com/dotconnect/mysql/

DevArt's connector supports EF and MySQL.

0

I didn't see the link here, but there's a beta .NET Connector for MySql. Click "Development Releases" to download 6.3.2 beta, which has EF4/VS2010 integration:

http://dev.mysql.com/downloads/connector/net/5.0.html#downloads

0

If you interested in running Entity Framework with MySql on mono/linux/macos, this might be helpful https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/

2
  • Is using MYSQL with EF got any better or there are still issues?if SQL server is preferable can anyone pinpoint exactly why SQL server is preferable just because its the same vendor Microsoft? Feb 18, 2017 at 2:45
  • I am not sure how it is right now, but we had pretty bad experience due to lack of features and it being overall inconsistent. MS MSQL is definitely preferable, because Microsoft puts it's own stack first. Feb 18, 2017 at 8:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.