将 MySQL 与实体框架结合使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/76488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:01:21  来源:igfitidea点击:

Using MySQL with Entity Framework

mysql.netentity-frameworkado.net

提问by vintana

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

在 Google 上找不到任何与 Entity Framework/MySQL 相关的信息,所以我希望有人知道。

回答by Vin

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

它已发布 - 获取适用于 .Net v6.5MySQL 连接器- 这支持 [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.

我一直在等待这个,虽然支持是基本的,但适用于数据库交互的大多数基本场景。它还具有基本的 Visual Studio 集成。

UPDATEhttp://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).

更新http://dev.mysql.com/downloads/connector/net/从 6.7 版开始,Connector/Net 将不再包含用于 Visual Studio 集成的 MySQL。该功能现在可在名为 MySQL for Visual Studio 的单独产品中使用,该产品使用适用于 Windows 的 MySQL 安装程序可用(请参阅http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html)。

回答by Sir Code-A-Lot

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

MySQL 将在几天内举办一个关于 EF 的网络研讨会......看这里: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

编辑:该网络研讨会现在在http://www.mysql.com/news-and-events/on-demand-webinars/display-od-204.html

回答by Sir Code-A-Lot

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:

这与 MS 和他们想要的无关。他们为其他人创建了一个*开放的系统来插入“提供者”——postgres 和 sqlite 有它——mysql 只是滞后...... /Net 6.0 将拥有它......你可以在这里查看:

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

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

回答by Lars Truijens

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

您需要一个 MySQL 的映射提供程序。这是实体框架需要让魔法发生的额外事情。本博客讨论了除 Microsoft 提供的映射服务提供商之外的其他映射服务提供商。我还没有发现任何关于 MySQL 的提及。

回答by aaimnr

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.

奇怪的是,现在已经准备好了。http://www.devart.com/products.html- 虽然它是商业的(你有 30 天的 IIRC 试用)。他们以写作提供者为生,所以我想它应该是快速和稳定的。我知道非常大的公司使用他们的 Oracle 提供商而不是 Orace 和 MS 提供商。

回答by scotru

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

您也可以查看https://www.devart.com/dotconnect/mysql/

DevArt's connector supports EF and MySQL.

DevArt 的连接器支持 EF 和 MySQL。

回答by oware

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

小心使用连接器 .net,连接器 6.6.5 有一个错误,它不能用于插入 tinyint 值作为身份,例如:

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.

直到现在我还没有找到解决方案,我不得不将我的 tinyint 身份更改为 unsigned int 身份,这解决了问题,但这不是正确的解决方案。

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

如果您使用旧版本的 Connector.net(我使用的是 6.4.4),则不会出现此问题。

If someone knows about the solution, please contact me.

如果有人知道解决方案,请与我联系。

Cheers!

干杯!

Oware

尾羽

回答by Igor Yalovoy

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/

如果您有兴趣在 mono/linux/macos 上使用 MySql 运行实体框架,这可能会有所帮助 https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/

回答by Brian Frantz

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:

我在这里没有看到链接,但有一个用于 MySql 的 beta .NET 连接器。点击“Development Releases”下载6.3.2 beta,集成EF4/VS2010:

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

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