积极答复者
Linq 动态查询问题 DynamicLibrary.cs

问题
-
用linq的动态查询(DynamicLibrary.cs 号称微软工程师提供的一个Linq动态查询类),代码如下
WhereStr = "RegisterTime>2010-1-1";
var getUserList = db.BBSUser.Where(WhereStr).ToList();
报错说Operator '>' incompatible with operand types 'DateTime?' and 'Int32'
我应该怎么拼接这个WhereStr 条件字符串中的日期呢? 我试过给日期加上 ‘’号或“”,都是报错。只是'Int32' 变为 char 或 String 不能跟日期型做比较。
网上资料太少,不知微软的专家能否指教一下。
谢谢!
答案
全部回复
-
用linq的动态查询(DynamicLibrary.cs 号称微软工程师提供的一个Linq动态查询类),代码如下
WhereStr = "RegisterTime>2010-1-1";
var getUserList = db.BBSUser.Where(WhereStr).ToList();
报错说Operator '>' incompatible with operand types 'DateTime?' and 'Int32'
我应该怎么拼接这个WhereStr 条件字符串中的日期呢? 我试过给日期加上 ‘’号或“”,都是报错。只是'Int32' 变为 char 或 String 不能跟日期型做比较。
网上资料太少,不知微软的专家能否指教一下。
谢谢!
有哪位专家来帮忙一下,万分感激! -
我看到网上有Dynamic.cs文件可以实现Linq to sql的动态查询,但是我不知道怎么才能使entity FrameWork也可以达到动态查询
- 已合并 Sheng Jiang 蒋晟Moderator 2010年6月11日 16:05
-
L2E要拼SQL的话用ObjectQuery.Where
var db = new NorthwindEntities();
var custs = db.Customers.Where("exists (select 1 from it.Orders)");
性能的话得找个DBA看,比如要做数据库设计、负载均衡、分区、索引等等。L2E自己不会修改程序员写的查询,所以程序员要写性能比较好的linq语句。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
你的查询里面有叫做TableName的字段?
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已建议为答案 Ali Kofi 2010年6月12日 6:46