268

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

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
vintana
  • 2,893
  • 2
  • 18
  • 12

10 Answers10

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).

NoWar
  • 36,338
  • 80
  • 323
  • 498
Vin
  • 6,115
  • 4
  • 41
  • 55
  • Thanks for the update, I was waiting for the same thing! – Alexandre Brisebois Jun 06 '09 at 14:25
  • 4
    I thought I'd mention that the latest version is available here (current 6.2.2): http://www.mysql.com/downloads/connector/net – Brett Ryan Mar 10 '10 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 – Abhijeet Patel May 13 '10 at 07:07
  • 1
    I'm curious about MySQL, EF4 and VS2010. – Vinicius Rocha Jun 29 '10 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 – David Anderson Aug 18 '11 at 03:30
  • It took me quite a while to find this so I wanted to share in case anyone else gets an "Out of sync with server" error running the latest version(6.4.3), it is a known bug fixed in version 6.4.4+. http://bugs.mysql.com/bug.php?id=61806 – Johnie Karr Sep 14 '11 at 01:48
  • If you experience an issue with the DatabaseInitializer take a look at the following link http://brice-lambson.blogspot.com/2012/05/using-entity-framework-code-first-with.html. – sky-dev Sep 10 '12 at 19:24
  • Example connection string for Code-first: – sky-dev Sep 10 '12 at 19:25
  • 1
    Ofcourse, there are new versions coming out. Now supporting EF5, version 6.7.4: http://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: http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html – Nullius Jul 19 '13 at 13:32
  • 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? – user3508811 Feb 18 '17 at 02:45
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/

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40
pattersonc
  • 1,282
  • 11
  • 13
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

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
Sir Code-A-Lot
  • 595
  • 6
  • 16
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

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.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
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.

aaimnr
  • 1,646
  • 1
  • 17
  • 31
  • Thank you for your response. @Vintana, you can find more information about dotConnect for MySQL and its advantages here http://www.devart.com/dotconnect/mysql/. To improve your work with Entity Framework entities we provide an advanced tool for visual model creation - Entity Developer http://www.devart.com/entitydeveloper/. – Devart Dec 07 '10 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

oware
  • 626
  • 9
  • 19
  • 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 '13 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 '13 at 15:22
  • The bug is fixed in version 6.8.2. http://bugs.mysql.com/bug.php?id=70888 Connector/Net 6.8.3 is released. http://dev.mysql.com/downloads/connector/net/ – Der_Meister Jan 10 '14 at 13:20
1

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

DevArt's connector supports EF and MySQL.

scotru
  • 2,563
  • 20
  • 37
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/

Igor Yalovoy
  • 1,715
  • 1
  • 17
  • 22
  • 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? – user3508811 Feb 18 '17 at 02: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. – Igor Yalovoy Feb 18 '17 at 08:51
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