Using MySQL with Entity Framework [closed]
Asked Answered
S

10

268

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

Skiest answered 16/9, 2008 at 20:18 Comment(2)
frankly speaking, mysql support for LINQ is crap! I am banging my head on minor issues for last one week :| ...Pyosis
did u use dblinq code.google.com/p/dblinq2007?Pignus
A
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).

Alleras answered 11/5, 2009 at 15:2 Comment(10)
Thanks for the update, I was waiting for the same thing!Nickeliferous
I thought I'd mention that the latest version is available here (current 6.2.2): mysql.com/downloads/connector/netPhlyctena
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 providersDustproof
I'm curious about MySQL, EF4 and VS2010.Duffie
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 MSSQLOjibwa
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+. bugs.mysql.com/bug.php?id=61806Bakery
If you experience an issue with the DatabaseInitializer take a look at the following link brice-lambson.blogspot.com/2012/05/….Finis
Example connection string for Code-first: <add name="MyDB" connectionString="Server=127.0.0.1;Port=3306;Database=MyDB;Uid=root;Pwd=;" providerName="MySql.Data.MySqlClient" />Finis
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/…Vday
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?Vanderbilt
C
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/

Crissman answered 3/4, 2009 at 3:12 Comment(4)
I fixed the encoding of that link - users can now click right through rather than have to copy/paste or select/gotoSuitcase
Link doesn't workAmphi
You can get to the articles with this link: pattersonc.com/blog/2009/04Zebulen
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?Vanderbilt
L
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

Locale answered 28/9, 2008 at 13:20 Comment(1)
Link is not working.Forworn
T
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

Twiddle answered 25/3, 2009 at 0:27 Comment(1)
I wonder what "initial" means when they said "Initial Entity Framework support".Skiest
C
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.

Cita answered 16/9, 2008 at 20:32 Comment(1)
Yeah, you're right. I was hoping there's something ready right now.Skiest
A
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.

Alumroot answered 6/11, 2009 at 11:36 Comment(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.Fanchet
G
1

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

DevArt's connector supports EF and MySQL.

Guienne answered 5/6, 2011 at 7:20 Comment(0)
R
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

Redbreast answered 27/4, 2013 at 15:58 Comment(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();Rootless
sorry I forgot to add the new line, even if I add the new line, the error stills appearingRedbreast
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/netGymnastics
F
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

Fletcherfletcherism answered 13/7, 2010 at 18:32 Comment(0)
H
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/

Horse answered 7/4, 2015 at 9:9 Comment(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?Vanderbilt
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.Horse

© 2022 - 2024 — McMap. All rights reserved.