日期:2014-05-17 浏览次数:20497 次
select * from User where 1=1
select * from User where 1=1 and DeptCode like '0041%' and PositionLevel > 3
#region 查询处理 var query_products = EF.V_OrderDetail.Where(a => a.ActionType == 0 && a.Company_ID == UserInfo.CompanyID); if (orderstate.HasValue) { query_products = query_products.Where(b => b.State==orderstate); } if (product.HasValue && product.Value > 0) { query_products = query_products.Where(b => b.Product_ID == product.Value); } if (datebegin != null && datebegin.IsDatetime()) { DateTime begin = datebegin.ToDateTimeShort(); query_products = query_products.Where(a => a.ActionTime >= begin); } if (dateend != null && dateend.IsDatetime()) { DateTime end = dateend.ToDateTimeShort().AddDays(1); query_products = query_products.Where(a => a.ActionTime < end); } if (!string.IsNullOrEmpty(disti_name)) { query_products = query_products.Where(a => a.CustomerCompany.Contains(disti_name)); } if (!string.IsNullOrEmpty(orderSN)) { query_products = query_products.Where(a => a.OrderSN.Contains(orderSN)); } #endregion
------解决方案--------------------
1L正解,如果要想进一步灵活控制查询条件生成,可以Google“Linq 表达式树”。