///// <summary>类型转换</summary> ///// <param name="obj"></param> ///// <returns></returns> //public static implicit operator String(ConcatExpression obj) //{ // return obj != null ? obj.GetString() : null; //} #endregion #region 重载运算符 /// <summary>重载运算符实现And操作</summary> /// <param name="exp"></param> /// <param name="value">数值</param> /// <returns></returns> public static ConcatExpression operator &(WhereExpression exp, ConcatExpression value) { var left = exp.GetString(); var ce = new ConcatExpression(left); if (value == null) return ce; //return ce.And(value.GetString()); // 条件表达式遇上连接表达式,不需要And或者逗号,只需要一个空格 ce.Builder.Append(" ").Append(value.GetString()); return ce; }
///// <summary>类型转换</summary> ///// <param name="obj"></param> ///// <returns></returns> //public static implicit operator String(ConcatExpression obj) //{ // return obj != null ? obj.GetString() : null; //} #endregion #region 重载运算符 /// <summary>重载运算符实现And操作</summary> /// <param name="exp"></param> /// <param name="value">数值</param> /// <returns></returns> public static ConcatExpression operator &(WhereExpression exp, ConcatExpression value) { var left = exp.GetString(); var ce = new ConcatExpression(left); if (value == null) { return(ce); } //return ce.And(value.GetString()); // 条件表达式遇上连接表达式,不需要And或者逗号,只需要一个空格 ce.Builder.Append(" ").Append(value.GetString()); return(ce); }
///// <summary>按照指定若干个字段分组。没有条件时使用分组请用FieldItem的GroupBy</summary> ///// <param name="where"></param> ///// <param name="fields"></param> ///// <returns>返回条件语句加上分组语句</returns> //public static ConcatExpression GroupBy(this WhereExpression where, params FieldItem[] fields) //{ // var exp = new ConcatExpression(); // var sb = exp.Builder; // where.GetString(sb, null); // if (sb.Length > 0) sb.Append(" Group By "); // for (var i = 0; i < fields.Length; i++) // { // if (i > 0) sb.Append(", "); // sb.Append(fields[i].FormatedName); // } // return exp; //} /// <summary>按照指定若干个字段分组。没有条件时使用分组请用FieldItem的GroupBy</summary> /// <param name="where"></param> /// <param name="fields"></param> /// <returns>将需要分组的字段作为ConcatExpression类型添加到whereExpression尾部</returns> public static WhereExpression GroupBy(this WhereExpression where, params FieldItem[] fields) { var exp = new ConcatExpression(); for (var i = 0; i < fields.Length; i++) { if (i == 0) { exp &= fields[i].GroupBy(); } exp.And(fields[i]); } return(new WhereExpression(where, Operator.Space, exp)); }
/// <summary>按照指定若干个字段分组。没有条件时使用分组请用FieldItem的GroupBy</summary> /// <param name="fields"></param> /// <returns>返回条件语句加上分组语句</returns> public static ConcatExpression GroupBy(this WhereExpression where, params FieldItem[] fields) { var exp = new ConcatExpression(); var sb = exp.Builder; where.GetString(sb, null); if (sb.Length > 0) { sb.Append(" Group By "); } for (var i = 0; i < fields.Length; i++) { if (i > 0) { sb.Append(", "); } sb.Append(fields[i].FormatedName); } return(exp); }