积极答复者
linq 动态关键字

问题
答案
-
终于搞定了,而且很强大啊
1.在这个上面下载:http://msdn2.microsoft.com/en-us/vcsharp/bb894665.aspx 动态linq code :Dynamic.cs 84k,放入到App_code里面
2.using System.Linq.Dynamic;
3.
string ordername = "中文名称.Length descending";
using (DataClassesDataContext myData = new DataClassesDataContext())
{
var allSearch = myData.Infodatabase.
Where("中文名称 .Contains(@0)", "王").
OrderBy(ordername).
Select("new(Number as 号, 中文名称)");
GridView1.DataSource = allSearch;
GridView1.DataBind();
}
这样就可以了,而且还支持,中文名称.Length 很简单啊
这个类库很好用 但是用到了一点反射 所以稍微有点慢。 但是应付复杂组合查询 目前来看这是最方便的办法
紫柔版主的头像真叫萌得一个不行啊。。。。
答案800 撒花- 已标记为答案 wanguan2000 2009年7月2日 5:50
全部回复
-
string 价格升序 = "ascending";
string 价格降序 = "descending";
怎么把这个关键字传递到linq里面?
var allSearch = from review in myData.Productantibody
where review.anti_GeneSymbol.Contains(qname)
// where review.anti_type.Contains(抗体类型)
orderby review.anti_price Eval("价格降序")
select review;
Eval("价格降序")
这样不行,有什么办法吗?
- 已合并 肖小勇Moderator 2009年7月1日 12:49
-
有一个代码类 叫做 dymic linq 可以通过分析字符串生成 expression 您搜索下就有了
紫柔版主的头像真叫萌得一个不行啊。。。。
答案800 撒花- 已建议为答案 韦恩卑鄙 waywa 2009年7月2日 4:31
-
orderby ("review.anti_price @0","ascending")
我看了下没有看懂:
string 价格升序 = "ascending";
string 价格降序 = "descending";
怎么把这个关键字传递到linq里面?
var allSearch = from review in myData.Productantibody
where review.anti_GeneSymbol.Contains(qname)
orderby ("review.anti_price @0",价格降序)
select review;
不行报错了,where的好像可以的。
http://www.scottgu.com/blogposts/dynquery/step5.png
这个图片上的 -
if (sortDescending){query = query.OrderByDescending(p => p.MessageDateTime);}else{query = query.OrderBy(p => p.MessageDateTime);}
Please mark the post answered your question as the answer, and mark other helpful posts as helpful. This posting is provided "AS IS" with no warranties, and confers no rights.
Visual C++ MVP -
终于搞定了,而且很强大啊
1.在这个上面下载:http://msdn2.microsoft.com/en-us/vcsharp/bb894665.aspx 动态linq code :Dynamic.cs 84k,放入到App_code里面
2.using System.Linq.Dynamic;
3.
string ordername = "中文名称.Length descending";
using (DataClassesDataContext myData = new DataClassesDataContext())
{
var allSearch = myData.Infodatabase.
Where("中文名称 .Contains(@0)", "王").
OrderBy(ordername).
Select("new(Number as 号, 中文名称)");
GridView1.DataSource = allSearch;
GridView1.DataBind();
}
这样就可以了,而且还支持,中文名称.Length 很简单啊 -
终于搞定了,而且很强大啊
1.在这个上面下载:http://msdn2.microsoft.com/en-us/vcsharp/bb894665.aspx 动态linq code :Dynamic.cs 84k,放入到App_code里面
2.using System.Linq.Dynamic;
3.
string ordername = "中文名称.Length descending";
using (DataClassesDataContext myData = new DataClassesDataContext())
{
var allSearch = myData.Infodatabase.
Where("中文名称 .Contains(@0)", "王").
OrderBy(ordername).
Select("new(Number as 号, 中文名称)");
GridView1.DataSource = allSearch;
GridView1.DataBind();
}
这样就可以了,而且还支持,中文名称.Length 很简单啊
这个类库很好用 但是用到了一点反射 所以稍微有点慢。 但是应付复杂组合查询 目前来看这是最方便的办法
紫柔版主的头像真叫萌得一个不行啊。。。。
答案800 撒花- 已标记为答案 wanguan2000 2009年7月2日 5:50