private static ExpEnity <T> Where <T>(this ExpEnity <T> expr1, Expression <Func <T, bool> > expr2, WhereType type) { var expr1Body = expr1.WhereExprBody; var name = $"{expr2.Parameters[0].Name}."; var bodyContent = Resolve(expr2).Replace(name, ""); foreach (var item in _whereFilter) { bodyContent = bodyContent.Replace(item.Key, item.Value); } var right = Expression.Constant( $"( {bodyContent} )" ); if (string.IsNullOrEmpty(expr1Body)) { expr1.WhereExpr = Expression.Lambda <Func <string> >(Expression.Constant($"{right}")); } else { expr1.WhereExpr = Expression.Lambda <Func <string> >(Expression.Constant($"{expr1Body} {type.ToString()} {right}")); } return(expr1); }
public static IEnumerable <T> Query <T>(this ExpEnity <T> expr1) { var condition = GetSQLCondition(expr1); LogUtil.InfoFormat(condition.VirtualExpression); return(expr1.Enity.Query(condition)); }
public static SQLPage <T> Query <T>(this ExpEnity <T> expr1, int pageSize, int currentPage) { var condition = GetSQLCondition(expr1); LogUtil.InfoFormat(condition.VirtualExpression); return(expr1.Enity.Query(pageSize, currentPage, condition)); }
private static SQLCondition GetSQLCondition <T>(ExpEnity <T> expr1) { var expression = string.IsNullOrEmpty(expr1.WhereExprBody) ? string.Empty : $" where { expr1.WhereExprBody }"; expression = expression + (string.IsNullOrEmpty(expr1.OrderExprBody) ? string.Empty : $"order by {expr1.OrderExprBody}"); return(new SQLCondition() { Expression = expression }); }
public static SQLPage <T> QueryPage <T>(this ExpEnity <T> expr1) { if (expr1.pageSize == -1 || expr1.currentPage == -1) { throw new Exception("未设置页码和当前页"); } var condition = GetSQLCondition(expr1); LogUtil.InfoFormat(condition.VirtualExpression); return(expr1.Enity.Query(expr1.pageSize, expr1.currentPage, condition)); }
private static ExpEnity <T> Order <T, V>(this ExpEnity <T> expr1, Expression <Func <T, V> > expr2, OrderType type) { var expr1Body = expr1.OrderExprBody; var name = $"{expr2.Parameters[0].Name}."; var bodyContent = Resolve(expr2).Replace(name, ""); var right = Expression.Constant( $"( {bodyContent} )" ); if (string.IsNullOrEmpty(expr1Body)) { expr1.OrderExpr = Expression.Lambda <Func <string> >(Expression.Constant($"{right} {type.ToString()}")); } else { expr1.OrderExpr = Expression.Lambda <Func <string> >(Expression.Constant($"{expr1Body} , {right} {type.ToString()}")); } return(expr1); }
public static ExpEnity <T> Page <T>(this ExpEnity <T> expr1, int pageSize, int currentPage) { expr1.pageSize = pageSize; expr1.currentPage = currentPage; return(expr1); }
public static ExpEnity <T> And <T>(this ExpEnity <T> expr1, Expression <Func <T, bool> > expr2) { return(Where(expr1, expr2, WhereType.AND)); }
public static ExpEnity <T> OrderAsc <T, V>(this ExpEnity <T> expr1, Expression <Func <T, V> > expr2) { return(Order(expr1, expr2, OrderType.ASC)); }