/// <summary> /// 根据C#表达式构造SQL语句 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="express"></param> /// <returns></returns> public virtual KeyValuePair <string, object>[] SelectMany <T>(out string sql, Expression <Func <T, bool> > express, string TableName) { var ex = express.Body; string sqlBase = SelectMany_Base(TableName); string whereStr = ""; var ret = ExpressionHandle.DealExpression(out whereStr, ex); sql = sqlBase + whereStr; return(ret); }
public virtual KeyValuePair <string, object>[] SelectPageListWithCondition <T>(out string sql, string Table, int pageSize, int nowPage, Expression <Func <T, bool> > condition, string[] orderBy = null, string orderType = "asc") { StringBuilder sb = new StringBuilder(); string whereStr = ""; KeyValuePair <string, object>[] conditions = null; sb.Append("select * from " + Table + ",(select count(*) as cnt from " + Table + ") as T" + " where "); if (condition != null) { conditions = ExpressionHandle.DealExpression(out whereStr, condition.Body); sb.Append(whereStr); sb.Append(" and "); } sb.Append("1=1 "); sql = sb.ToString() + OrderByString(orderType, orderBy) + LimitString(pageSize, nowPage); return(conditions); }
public override KeyValuePair <string, object>[] SelectPageListWithCondition <T>(out string sql, string Table, int pageSize, int nowPage, Expression <Func <T, bool> > condition, string[] orderBy = null, string orderType = "asc") { KeyValuePair <string, object>[] ret = null; string whereStr = ""; StringBuilder sb = new StringBuilder(); sb.Append(" where "); if (condition != null) { ret = ExpressionHandle.DealExpression(out whereStr, condition.Body); sb.Append(whereStr); sb.Append(" and "); } sb.Append("1=1 "); whereStr = sb.ToString(); int star = (nowPage - 1) * pageSize + 1; int end = star + pageSize - 1; sql = "select * from(select ROW_NUMBER()over(" + OrderByString(orderType, orderBy) + ") rowID,* from " + Table + " " + whereStr + ") as tbq,(select count(*) cnt from " + Table + ") as tb where tbq.rowID between " + star + " and " + end + ";"; return(ret); }