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

2019-02-09 02:28发布

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?

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

6条回答
贪生不怕死
2楼-- · 2019-02-09 02:41

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

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.

查看更多
做自己的国王
3楼-- · 2019-02-09 02:43

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

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

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.


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.

查看更多
beautiful°
4楼-- · 2019-02-09 02:50

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.

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.

查看更多
戒情不戒烟
5楼-- · 2019-02-09 02:51

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.

查看更多
在下西门庆
6楼-- · 2019-02-09 02:53

According to the Mono roadmap I'm not sure if Linq is available for 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)

查看更多
地球回转人心会变
7楼-- · 2019-02-09 03:01

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

查看更多
登录 后发表回答