我一直试图让
Linq在Ubuntu上使用Mysql,在存储库(2.10.5)中使用Mono版本,我只会头疼.
首先,我不得不修改MySQL提供程序sqlmetal.exe.config,因为它默认设置为旧的和不推荐使用的版本,我设法让它工作设置我在这台机器上安装的MySQL连接器(来自存储库) )作为sqlmetal的提供者.我为我的目标数据库生成了带有sqlmetal的DataContext,这似乎有效,但我不完全确定.
在生成DataContext之后,我在monodevelop上创建了一个新项目来测试它,起初我尝试使用一个简单的MysqlConenction并检查连接器是否正常工作,我不得不将连接器组件添加到项目中,但这没关系,它工作正常.
然后我尝试使用此代码使用DataContext进行连接:
using System;
using System.Linq;
using System.Data.Linq;
using MySql.Data.MySqlClient;
namespace test
{
public class test
{
public static void Main (String[] args)
{
Test db = new Test (new MySqlConnection("Userid=root;database=test;server=localhost;password=password"));
foreach(var tr in db.Users)
{
Console.Write(tr.Username);
}
}
}
}
此代码失败.似乎Linq正在为MySQL生成错误的SQL代码,至少它抛出的异常似乎是这样说的:
Unhandled Exception: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Id], [Password], [Username]
FROM [test].[Users]' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in :0
at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Id], [Password], [Username]
FROM [test].[Users]' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in :0
at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in :0
有谁知道是否可以使用Linq和Mono连接到MySQL?有什么我想念的吗?
谢谢!