我一直在試圖讓Linq與Ubuntu上的Mysql一起使用,使用版本庫中的單聲道版本(2.10.5),而且我什麼也得不到,但頭痛。讓Linq和Mysql和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的不良生成SQL代碼爲MySQL,至少它拋出異常似乎是在說:
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 <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in <filename unknown>: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 <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32& affectedRow, System.Int32& insertedId) [0x00000] in <filename unknown>:0
有誰知道是否有可能連接到MySQL使用LINQ和Mono?有什麼我失蹤?
謝謝!
這個問題已經被這裏討論 http://stackoverflow.com/questions/42212/how-can-i-use-linq-with-a-mysql-database-on-mono – Eugene
我讀的問題,但這是一個3歲的問題,我認爲事情會改變... – uorbe001