日期:2014-05-17  浏览次数:21001 次

Lambda如何实现动态SQL语句?
用Lambda如何实现如下SQL语句构建,if(a!=""){sql="a=123"} if(b!="")(sql+="b=123")

------解决方案--------------------
C# code
var query = db.TableName;
if (a != "")
    query = query.Where(x => x.a == a);
if (b != "")
    query = query.Where(x => x.b == b);
//query = db.TableName.Where(x => x.a == a && x.b == b);