using System; using System.Linq; using System.Linq.Expressions; namespace Oyang.Tool { public static class PredicateBuilder { public static Expression<Func<T, bool>> True<T>() { return f => true; } public static Expression<Func<…
很多情况下,我们开发程序,需要动态拼接SQL查询语句; 比如 select top 1 * from User where age= 18 and name = 'renruiquan' 其中红色的代码,是我们需要根据查询条件是否为空,来判,要不要加在查询的SQL里; 换成Linq里就不能这么直接的去拼接了,好在国外的大神有给我们解决方案.下面直接上代码: (新手同学不需要关心代码具体是怎么实现的,只需要知道怎么调用就好.当然,你能研究一下,给自己充电,也是再好不过了) using Sys…