新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
LINQtoSQL動態(tài)查詢概括
LINQ to SQL有很多值得學(xué)習(xí)的地方,這里我們主要介紹LINQ to SQL動態(tài)查詢,包括介紹LINQ to SQL功能和調(diào)試特定等方面

LINQ to SQL動態(tài)查詢
使用LINQ to SQL動態(tài)查詢,這個例子用CreateQuery()方法創(chuàng)建一個IQueryable
這里給個例子說明一下:
- var c1 = Expression.Parameter(typeof(Customer), "c");
- PropertyInfo City = typeof(Customer).GetProperty("City");
- var pred = Expression.Lambda
, bool>>( - Expression.Equal(
- Expression.Property(c1, City),
- Expression.Constant("Seattle")
- ), c1
- );
- IQueryable custs = db.Customers;
- Expression expr = Expression.Call(typeof(Queryable), "Where",
- new Type[] { custs.ElementType }, custs.Expression, pred);
- IQueryable
q = db.Customers.AsQueryable(). - Provider.CreateQuery
(expr);
Log屬性用于將SQL查詢或命令打印到TextReader。此方法對了解 LINQ to SQL功能和調(diào)試特定的問題可能很有用。
下面的示例使用Log屬性在SQL代碼執(zhí)行前在控制臺窗口中顯示此代碼。我們可以將此屬性與查詢、插入、更新和刪除命令一起使用。
- //關(guān)閉日志功能
- //db.Log = null;
- //使用日志功能:日志輸出到控制臺窗口
- db.Log = Console.Out;
- var q = from c in db.Customers
- where c.City == "London"
- select c;
- //日志輸出到文件
- StreamWriter sw = new StreamWriter(Server.MapPath("log.txt"), true);
- db.Log = sw;
- var q = from c in db.Customers
- where c.City == "London"
- select c;
- sw.Close();
分享題目:LINQtoSQL動態(tài)查詢概括
標(biāo)題URL:http://fisionsoft.com.cn/article/dpjgceo.html


咨詢
建站咨詢
