網誌分類:Programming |
今日試過 Linq to MySQL
WebSite: http://linq.to/
All linq flavors: http://linq.to/AllFlavors
會有齊 Linq to ??? 的 Status.
今日 Download 左 DBLinq 0.16
Google Code: http://code.google.com/p/dblinq2007/downloads/list
裡面有 16 個 Project.
試佢裡面的 Example 就無問題. 但想寫自己野就開始有困難.
因為佢唔可以好似 Linq to SQL 有個 UI Drag & Drop Table 去個 DatabaseContext. 要用佢個 SqlMetal Project to Generate 個 Class.
i.e. SqlMetal.exe --provider=MySql -database:[DB NAME] -server:[SERVER IP/NAME] -user:[DB User] -password:[DB Password] -namespace:[NAMESPACE] -code:[Generate Code File Name]
試左開個 New Project.
要 Add Reference: DbLinq, DbLinq.MySql, System.Data, System.Data.Linq
抄個 Generated File 去個 Project 度. 跟埋個 NameSpace.
試左好簡單的 Linq.
string connStr = "server=192.168.5.1;user id=remote; password=remote; database=remote_test";
remote.remote_test db = new remote.remote_test(new MySql.Data.MySqlClient.MySqlConnection(connStr));
db.Log = Console.Out;
var query = from c in db.TB1
//where c.field_1 == "1"
select c;
this.dataGridView1.DataSource = query.ToList() ;
個 Output 有這些 Log.
MTable.CreateQuery: value(DbLinq.Linq.Table`1[remote.TB1]).Select(c => c)
SQL: SELECT x$.id, x$.field_1, x$.field_2, x$.field_3, x$.field_4, x$.field_5
FROM tb1 x$
RowEnum.Dispose()
如果有 Where 就有這些
MTable.CreateQuery: value(DbLinq.Linq.Table`1[remote.TB1]).Where(c => (c.field_1 = "1"))
SQL: SELECT c$.id, c$.field_1, c$.field_2, c$.field_3, c$.field_4, c$.field_5
FROM tb1 c$ WHERE c$.field_1 = ?P0
RowEnum.Dispose()
SQL PARAM: ?P0 = 1
其他研究緊. 看下點玩.

