/// <summary> /// Between和NOT Between的情况 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ToSQLWithBetween(ParseSqlContext context) { System.Data.Common.DbParameter parameter = context.CreateParameter(this.column.name, value); context.DbParameters.Add(parameter); System.Data.Common.DbParameter parameter2 = context.CreateParameter(this.column.name, value2); context.DbParameters.Add(parameter2); return(string.Format("{0} {3} {1} AND {2}", this.column.Parse(context), parameter.ParameterName, parameter2.ParameterName, this.opt.ToSql())); }
/// <summary> /// IN和NOT IN的情况 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ToSQLWithIN(ParseSqlContext context) { var lstParameter = lstValue.Select(x => context.CreateParameter(this.column.name, x)).ToList(); context.DbParameters.AddRange(lstParameter); var lstParameterName = lstParameter.Select(x => x.ParameterName).ToList(); return(string.Format("{0} {1} ({2})", this.column.Parse(context), this.opt.ToSql(), string.Join(",", lstParameterName))); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override string Parse(ParseSqlContext context) { switch (this.opt) { case WhereOpt.IN: return(this.ToSQLWithIN(context)); case ~WhereOpt.IN: return(this.ToSQLWithIN(context)); case WhereOpt.BT: return(this.ToSQLWithBetween(context)); case ~WhereOpt.BT: return(this.ToSQLWithBetween(context)); case WhereOpt.NoParameter: return(this.ToSQLWithNoParameter(context)); case WhereOpt.NULL: return(this.ToSQLWithNULL(context)); case ~WhereOpt.NULL: return(this.ToSQLWithNULL(context)); case WhereOpt.Exists: return(this.ToSQLWithExists(context)); case ~WhereOpt.Exists: return(this.ToSQLWithExists(context)); default: break; } DbParameter parameter = context.CreateParameter(this.column.name, value); string strwhere = string.Format("{0} {1} {2}", this.column.Parse(context), this.opt.ToSql(), parameter.ParameterName); //表别名.列1=参数1 context.DbParameters.Add(parameter); return(strwhere); }