C# 如何在 Mono 上将 Linq 与 MySql 数据库一起使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42212/
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-03 09:51:44  来源:igfitidea点击:

How can I use Linq with a MySql database on Mono?

提问by skolima

There are numerous libraries providing Linq capabilities to C# code interacting with a MySql database. Which one of them is the most stable and usable on Mono?

有许多库为与 MySql 数据库交互的 C# 代码提供 Linq 功能。其中哪一个在 Mono 上最稳定、最可用?

Background (mostly irrelevant): I have a simple C# (.Net 2.0) program updating values in a MySql database. It is executed nightly via a cron job and runs on a Pentium 3 450Mhz, Linux + Mono. I want to rewrite it using Linq (.Net 3.5) mostly as an exercise (I have not yet used Linq).

背景(大部分无关):我有一个简单的 C# (.Net 2.0) 程序更新 MySql 数据库中的值。它每晚通过 cron 作业执行,并在 Pentium 3 450Mhz、Linux + Mono 上运行。我想使用 Linq (.Net 3.5) 重写它,主要是作为练习(我还没有使用过 Linq)。

采纳答案by Adam Lassek

The only (free) linq provider for MySql is DbLinq, and I believe it is a long way from production-ready.

MySql 的唯一(免费)linq 提供程序是DbLinq,我相信它离生产就绪还有很长的路要走。

There is also MyDirect.Netwhich is commercial, but I have heard mixed reviews of it's capability.

还有商业版的MyDirect.Net,但我听到了对其功能的褒贬不一的评价。

I've read that MySql will be implementing the Linq to Entities API for the 5.3 version of the .net connector, but I don't know if there's even a timeline for that. In fact, MySql has been totally silent about Entity Framework support for months.

我已经读到 MySql 将为 5.3 版本的 .net 连接器实现 Linq to Entities API,但我不知道是否有时间表。事实上,MySql 几个月来一直对实体框架支持完全保持沉默。



Addendum: The latest release of the MySql Connector/Net 6.0 has support for the EF according to the release notes. I have no idea how stable/useful this is, so I'd love to hear from anybody who have tried it.

附录:最新版本的 MySql Connector/Net 6.0 根据发行说明支持 EF。我不知道这有多稳定/有用,所以我很想听听任何尝试过它的人的意见。

回答by John Boker

at this time you cannot use linq to sql, you might look into a third party linq mysql provider or linq to entities. linq to sql only works for sql server databases.

此时您不能使用 linq to sql,您可以查看第三方 linq mysql provider 或 linq to entity。linq to sql 仅适用于 sql server 数据库。

回答by FlySwat

LINQ to SQL is simply a ORM layer leveraging the power of expressions to make it easy to construct queries in your code.

LINQ to SQL 只是一个 ORM 层,利用表达式的强大功能可以轻松地在代码中构建查询。

If you are just calling adhoc queries for your tool, there is little need to use LINQ, it just adds an extra layer of abstraction to your code.

如果您只是为您的工具调用即席查询,则几乎不需要使用 LINQ,它只是为您的代码添加了一个额外的抽象层。

回答by Douglas Leeder

According to the Mono roadmapI'm not sure if Linq is available for mono?

根据Mono 路线图,我不确定 Linq 是否可用于 Mono?

At least some of Linq might be available in the very latest release, but Linq to DB is listed for Mono 2.4 (Feb 2009)

至少有一些 Linq 可能在最新版本中可用,但 Linq to DB 已在 Mono 2.4(2009 年 2 月)中列出

回答by marclar

Not sure about Mono, but I just started using LightSpeedand that supports LINQ-to-MySQL.

不确定 Mono,但我刚开始使用LightSpeed并且支持 LINQ-to-MySQL。

回答by Opflash

I have tried the tutorial at http://www.primaryobjects.com/CMS/Article100.aspx. This uses dblinq/dbmetal to generate the data context class and classes for each table.

我已经在http://www.primaryobjects.com/CMS/Article100.aspx尝试了教程。这使用 dblinq/dbmetal 为每个表生成数据上下文类和类。

The code failed at the first attempt with an unhandled exception (MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime"). Googling revealed this should be easily solved by appending "Allow Zero Datetime=True;" to the connection string. Unfortionately this turned out not to solve my problem. Thinking the MySQL .Net Connector was to blame I executed the SQL generated by dblinq without the linq2sql intermediary layer using the MySQL Connector. This time no exception occured. Tables which do not have a date column did work with DbLinq. So, from my experiment I agree with Adam, DbLinq is a long way from production ready.

代码在第一次尝试时失败,出现未处理的异常 (MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime")。谷歌搜索显示这应该很容易通过附加“Allow Zero Datetime=True”来解决;" 到连接字符串。不幸的是,这并没有解决我的问题。认为 MySQL .Net 连接器是罪魁祸首,我使用 MySQL 连接器在没有 linq2sql 中间层的情况下执行了 dblinq 生成的 SQL。这次没有发生异常。表它没有日期列确实与 DbLinq 一起工作。所以,从我的实验来看,我同意 Adam 的观点,DbLinq 距离生产就绪还有很长的路要走。