/// <summary> /// 设置连接条件 /// </summary> /// <typeparam name="TLeft">左表实体类型</typeparam> /// <typeparam name="TRight">右表实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="left">左表列名</param> /// <param name="right">右表列名</param> /// <param name="operator">条件运算符</param> /// <returns></returns> public static ISqlQuery On <TLeft, TRight>(this ISqlQuery sqlQuery, Expression <Func <TLeft, object> > left, Expression <Func <TRight, object> > right, Operator @operator = Operator.Equal) where TLeft : class where TRight : class { var builder = sqlQuery.GetBuilder(); builder.On(left, right, @operator); return(sqlQuery); }
/// <summary> /// 设置连接条件 /// </summary> /// <typeparam name="TLeft">左表实体类型</typeparam> /// <typeparam name="TRight">右表实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">条件表达式</param> /// <returns></returns> public static ISqlQuery On <TLeft, TRight>(this ISqlQuery sqlQuery, Expression <Func <TLeft, TRight, bool> > expression) where TLeft : class where TRight : class { var builder = sqlQuery.GetBuilder(); builder.On(expression); return(sqlQuery); }
/// <summary> /// 添加Sql参数 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="name">参数名</param> /// <param name="value">参数值</param> public static ISqlQuery AddParam(this ISqlQuery sqlQuery, string name, object value) { var builder = sqlQuery.GetBuilder(); builder.AddParam(name, value); return(sqlQuery); }
/// <summary> /// 清空Join子句 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> public static ISqlQuery ClearJoin(this ISqlQuery sqlQuery) { var builder = sqlQuery.GetBuilder(); builder.ClearJoin(); return(sqlQuery); }
/// <summary> /// 设置非空条件,范例:[Name] Is Null Or [Name]<>'' /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <returns></returns> public static ISqlQuery IsNotEmpty <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.IsNotEmpty(expression); return(sqlQuery); }
/// <summary> /// 设置范围查询条件 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> /// <param name="boundary">包含边界</param> /// <returns></returns> public static ISqlQuery Between <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, decimal?min, decimal?max, Boundary boundary = Boundary.Both) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Between(expression, min, max, boundary); return(sqlQuery); }
/// <summary> /// 分组 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="column">分组字段,范例:t => t.Name</param> /// <param name="having">分组条件,范例:Count(*) > 1</param> /// <returns></returns> public static ISqlQuery GroupBy <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > column, string having = null) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.GroupBy(column, having); return(sqlQuery); }
/// <summary> /// 设置查询条件 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="value">值,如果该值为空,则忽略该查询条件</param> /// <param name="operator">运算符</param> /// <returns></returns> public static ISqlQuery WhereIfNotEmpty <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, object value, Operator @operator = Operator.Equal) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.WhereIfNotEmpty(expression, value, @operator); return(sqlQuery); }
/// <summary> /// 设置列名 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="propertyAsAlias">是否将属性名映射为列别名</param> public static ISqlQuery Select <TEntity>(this ISqlQuery sqlQuery, bool propertyAsAlias = false) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Select <TEntity>(propertyAsAlias); return(sqlQuery); }
/// <summary> /// 分组 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="columns">分组字段</param> public static ISqlQuery GroupBy <TEntity>(this ISqlQuery sqlQuery, params Expression <Func <TEntity, object> >[] columns) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.GroupBy(columns); return(sqlQuery); }
/// <summary> /// 添加范围查询条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="min">最小值</param> /// <param name="max">最大值</param> /// <param name="includeTime">是否包含时间</param> /// <param name="boundary">包含边界</param> public static ISqlQuery Between <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, DateTime?min, DateTime?max, bool includeTime = true, Boundary?boundary = null) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Between(expression, min, max, includeTime, boundary); return(sqlQuery); }
/// <summary> /// 设置Not In条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="action">子查询操作</param> public static ISqlQuery NotIn <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, Action <ISqlBuilder> action) where TEntity : class { var sqlBuilder = sqlQuery.GetBuilder(); sqlBuilder.NotIn(expression, action); return(sqlQuery); }
/// <summary> /// 设置In条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="builder">Sql生成器</param> public static ISqlQuery In <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, ISqlBuilder builder) where TEntity : class { var sqlBuilder = sqlQuery.GetBuilder(); sqlBuilder.In(expression, builder); return(sqlQuery); }
/// <summary> /// Or连接条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="condition">该值为true时添加查询条件,否则忽略</param> /// <param name="predicates">查询条件</param> public static ISqlQuery OrIf <TEntity>(this ISqlQuery sqlQuery, bool condition, params Expression <Func <TEntity, bool> >[] predicates) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.OrIf(condition, predicates); return(sqlQuery); }
/// <summary> /// 排序 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="column">排序列</param> /// <param name="desc">是否倒序</param> /// <returns></returns> public static ISqlQuery OrderBy <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > column, bool desc = false) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.OrderBy(column, desc); return(sqlQuery); }
/// <summary> /// 设置查询条件 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">查询条件表达式,范例:t => t.Name.Contains("a") && ( t.Code == "b" || t.Age > 1 )</param> /// <param name="condition">拼接条件,该值为true时添加查询条件,否则忽略</param> /// <returns></returns> public static ISqlQuery WhereIf <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, bool> > expression, bool condition) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.WhereIf(expression, condition); return(sqlQuery); }
/// <summary> /// 设置获取行数 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="count">获取的行数</param> public static ISqlQuery Take(this ISqlQuery sqlQuery, int count) { var builder = sqlQuery.GetBuilder(); builder.Take(count); return(sqlQuery); }
/// <summary> /// 设置尾匹配查询条件 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="value">值</param> /// <returns></returns> public static ISqlQuery Ends <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, object value) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Ends(expression, value); return(sqlQuery); }
/// <summary> /// 设置列名 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="columns">列名,范例:t => new object[] { t.Id, t.Name }</param> /// <param name="propertyAsAlias">是否将属性名映射为列别名</param> /// <returns></returns> public static ISqlQuery Select <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object[]> > columns, bool propertyAsAlias = false) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Select(columns, propertyAsAlias); return(sqlQuery); }
/// <summary> /// 设置Not In条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式</param> /// <param name="values">值集合</param> public static ISqlQuery NotIn <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, IEnumerable <object> values) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.NotIn(expression, values); return(sqlQuery); }
/// <summary> /// 设置列名 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="column">列名,范例:t => t.A,支持字典批量设置列和列别名, /// 范例:Select<Sample>( t => new Dictionary<object, string> { { t.Email, "e" }, { t.Url, "u" } } );</param> /// <param name="columnAlias">列别名</param> /// <returns></returns> public static ISqlQuery Select <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > column, string columnAlias = null) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.Select(column, columnAlias); return(sqlQuery); }
/// <summary> /// 清空分页参数 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> public static ISqlQuery ClearPageParams(this ISqlQuery sqlQuery) { var builder = sqlQuery.GetBuilder(); builder.ClearPageParams(); return(sqlQuery); }
/// <summary> /// 右外连接 /// </summary> /// <typeparam name="TEntity">实体类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="alias">别名</param> /// <param name="schema">架构名</param> /// <returns></returns> public static ISqlQuery RightJoin <TEntity>(this ISqlQuery sqlQuery, string alias = null, string schema = null) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.RightJoin <TEntity>(alias, schema); return(sqlQuery); }
/// <summary> /// 忽略过滤器 /// </summary> /// <typeparam name="TSqlFilter">Sql过滤器类型</typeparam> /// <param name="sqlQuery">Sql查询对象</param> public static ISqlQuery IgnoreFilter <TSqlFilter>(this ISqlQuery sqlQuery) where TSqlFilter : ISqlFilter { var builder = sqlQuery.GetBuilder(); builder.IgnoreFilter <TSqlFilter>(); return(sqlQuery); }
/// <summary> /// Or连接条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="conditions">查询条件。如果表达式中的值为空,则忽略该查询条件</param> public static ISqlQuery OrIfNotEmpty <TEntity>(this ISqlQuery sqlQuery, params Expression <Func <TEntity, bool> >[] conditions) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.OrIfNotEmpty(conditions); return(sqlQuery); }
/// <summary> /// 移除列名 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="column">列名,范例:t => t.Name,支持字典批量设置列和列别名</param> public static ISqlQuery RemoveSelect <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > column) where TEntity : class { var builder = sqlQuery.GetBuilder(); builder.RemoveSelect(column); return(sqlQuery); }
/// <summary> /// 设置子查询条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式,范例:t => t.Name</param> /// <param name="action">子查询操作</param> /// <param name="condition">该值为true时添加查询条件,否则忽略</param> /// <param name="operator">运算符</param> public static ISqlQuery WhereIf <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, Action <ISqlBuilder> action, bool condition, Operator @operator = Operator.Equal) where TEntity : class { var sqlBuilder = sqlQuery.GetBuilder(); sqlBuilder.WhereIf(expression, action, condition, @operator); return(sqlQuery); }
/// <summary> /// 设置子查询条件 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> /// <param name="expression">列名表达式</param> /// <param name="builder">子查询Sql生成器</param> /// <param name="operator">运算符</param> public static ISqlQuery Where <TEntity>(this ISqlQuery sqlQuery, Expression <Func <TEntity, object> > expression, ISqlBuilder builder, Operator @operator = Operator.Equal) where TEntity : class { var sqlBuilder = sqlQuery.GetBuilder(); sqlBuilder.Where(expression, builder, @operator); return(sqlQuery); }
/// <summary> /// 获取调试Sql语句 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> public static string GetDebugSql(this ISqlQuery sqlQuery) { var builder = sqlQuery.GetBuilder(); return(builder.ToDebugSql()); }
/// <summary> /// 创建一个新的Sql生成器 /// </summary> /// <param name="sqlQuery">Sql查询对象</param> public static ISqlBuilder NewBuilder(this ISqlQuery sqlQuery) { var builder = sqlQuery.GetBuilder(); return(builder.New()); }