mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-29 09:54:44 +08:00
Update Core
This commit is contained in:
@@ -39,29 +39,21 @@ namespace OrmTest.UnitTest
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] ORDER BY [ID] ASC", null, t3.Key, null, "single t3 Error");
|
||||
|
||||
var t4 = db.Queryable<Student>().OrderBy(it => it.Id).Take(3).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 1 AND 3", null, t4.Key, null, "single t4 Error");
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 1 AND 3", null, t4.Key, null, "single t4 Error");
|
||||
|
||||
var t5 = db.Queryable<Student>().OrderBy(it => it.Id).Skip(3).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, t5.Key,null, "single t5 Error");
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] ASC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 4 AND 9223372036854775807", null, t5.Key, null, "single t5 Error");
|
||||
|
||||
int pageIndex = 2;
|
||||
int pageSize = 10;
|
||||
var t6 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent]
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", null, t6.Key, null, "single t6 Error");
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM [STudent] ) T WHERE RowIndex BETWEEN 11 AND 20", null, t6.Key, null, "single t6 Error");
|
||||
|
||||
|
||||
int studentCount = db.Ado.GetInt("select count(1) from Student");
|
||||
var countIsSuccess = db.Queryable<Student>().Count() == studentCount;
|
||||
if (!countIsSuccess) {
|
||||
if (!countIsSuccess)
|
||||
{
|
||||
throw new Exception(" single countIsSuccess Error");
|
||||
}
|
||||
|
||||
@@ -104,10 +96,7 @@ namespace OrmTest.UnitTest
|
||||
.Where(it => it.Id == 1)
|
||||
.WhereIF(true, it => SqlFunc.Contains(it.Name, "a"))
|
||||
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).With(SqlWith.NoLock).ToSql();
|
||||
base.Check(@"WITH PageTable AS(
|
||||
SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK) WHERE ( [ID] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%')
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||
base.Check(@"SELECT * FROM (SELECT [ID],[SchoolId],[Name],[CreateTime],ROW_NUMBER() OVER(ORDER BY [ID] DESC) AS RowIndex FROM [STudent] WITH(NOLOCK) WHERE ( [ID] = @Id0 ) AND ([Name] like '%'+@MethodConst1+'%') ) T WHERE RowIndex BETWEEN 11 AND 20", new List<SugarParameter>() {
|
||||
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
|
||||
}, t8.Key, t8.Value, "single t8 Error");
|
||||
|
||||
|
||||
@@ -107,8 +107,8 @@ namespace SqlSugar
|
||||
foreach (var property in result.Type.GetProperties())
|
||||
{
|
||||
EntityColumnInfo column = new EntityColumnInfo();
|
||||
var isVirtual = property.GetGetMethod().IsVirtual;
|
||||
if (isVirtual) continue;
|
||||
//var isVirtual = property.GetGetMethod().IsVirtual;
|
||||
//if (isVirtual) continue;
|
||||
var sugarColumn = property.GetCustomAttributes(typeof(SugarColumn), true)
|
||||
.Where(it => it is SugarColumn)
|
||||
.Select(it => (SugarColumn)it)
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace SqlSugar
|
||||
public virtual ISugarQueryable<T> PartitionBy(Expression<Func<T, object>> expression)
|
||||
{
|
||||
if (QueryBuilder.Take == null)
|
||||
QueryBuilder.Take = 0;
|
||||
QueryBuilder.Take = 1;
|
||||
_PartitionBy(expression);
|
||||
return this;
|
||||
}
|
||||
@@ -405,10 +405,9 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual TResult Max<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Max<TResult>(lamResult.GetResultString());
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
|
||||
public virtual TResult Min<TResult>(string minField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.MinTemplate, minField));
|
||||
@@ -417,10 +416,9 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual TResult Min<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Min<TResult>(lamResult.GetResultString());
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
|
||||
public virtual TResult Sum<TResult>(string sumField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.SumTemplate, sumField));
|
||||
@@ -429,10 +427,9 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual TResult Sum<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Sum<TResult>(lamResult.GetResultString());
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
|
||||
public virtual TResult Avg<TResult>(string avgField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.AvgTemplate, avgField));
|
||||
@@ -441,11 +438,8 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual TResult Avg<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Avg<TResult>(lamResult.GetResultString());
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
|
||||
public virtual string ToJson()
|
||||
{
|
||||
return this.Context.RewritableMethods.SerializeObject(this.ToList());
|
||||
@@ -495,6 +489,9 @@ namespace SqlSugar
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
totalNumber = this.Count();
|
||||
if (totalNumber == 0)
|
||||
return new List<T>();
|
||||
else
|
||||
return ToPageList(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
@@ -549,6 +546,30 @@ namespace SqlSugar
|
||||
GroupBy(result);
|
||||
return this;
|
||||
}
|
||||
protected TResult _Min<TResult>(Expression expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Min<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
protected TResult _Avg<TResult>(Expression expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Avg<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
protected TResult _Max<TResult>(Expression expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Max<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
protected TResult _Sum<TResult>(Expression expression)
|
||||
{
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Sum<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
public ISugarQueryable<T> _PartitionBy(Expression expression)
|
||||
{
|
||||
LambdaExpression lambda = expression as LambdaExpression;
|
||||
@@ -726,6 +747,25 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T3
|
||||
@@ -835,6 +875,24 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2,T3, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T4
|
||||
@@ -964,6 +1022,25 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, T3,T4, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, T3,T4, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, T3,T4, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, T3,T4, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T5
|
||||
@@ -1119,6 +1196,25 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, T3, T4,T5, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, T3, T4,T5, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, T3, T4,T5, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, T3, T4,T5, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T6
|
||||
@@ -1300,6 +1396,25 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5,T6, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5,T6, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5,T6, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5,T6, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T7
|
||||
@@ -1508,6 +1623,25 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#region T8
|
||||
@@ -1742,6 +1876,25 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
public TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression)
|
||||
{
|
||||
return _Max<TResult>(expression);
|
||||
}
|
||||
public TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression)
|
||||
{
|
||||
return _Min<TResult>(expression);
|
||||
}
|
||||
public TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression)
|
||||
{
|
||||
return _Sum<TResult>(expression);
|
||||
}
|
||||
public TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression)
|
||||
{
|
||||
return _Avg<TResult>(expression);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -124,10 +124,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"WITH PageTable AS(
|
||||
{0}
|
||||
)
|
||||
SELECT * FROM (SELECT *,ROW_NUMBER() OVER({1}) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN {2} AND {3}";
|
||||
return @"SELECT * FROM ({0}) T WHERE RowIndex BETWEEN {1} AND {2}";
|
||||
}
|
||||
}
|
||||
public virtual string DefaultOrderByTemplate
|
||||
@@ -232,34 +229,27 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
sql = new StringBuilder();
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
|
||||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
var isRowNumber = Skip != null || Take != null;
|
||||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos,(!isRowNumber&&this.OrderByValue.IsValuable())?GetOrderByString:null);
|
||||
sql.Replace("{$:OrderByString:$}", isRowNumber? (this.IsCount?null: rowNumberString): null);
|
||||
if (IsCount) { return sql.ToString(); }
|
||||
if (Skip != null && Take == null)
|
||||
{
|
||||
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, long.MaxValue);
|
||||
return string.Format(PageTempalte, sql.ToString(), Skip.ObjToInt() + 1, long.MaxValue);
|
||||
}
|
||||
else if (Skip == null && Take != null)
|
||||
{
|
||||
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, 1, Take.ObjToInt());
|
||||
return string.Format(PageTempalte, sql.ToString(), 1, Take.ObjToInt());
|
||||
}
|
||||
else if (Skip != null && Take != null)
|
||||
{
|
||||
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
|
||||
if (this.PartitionByValue.IsValuable())
|
||||
{
|
||||
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
|
||||
}
|
||||
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt());
|
||||
return string.Format(PageTempalte, sql.ToString(), Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -405,19 +395,11 @@ namespace SqlSugar
|
||||
if (this.OrderByValue == null) return null;
|
||||
if (IsCount) return null;
|
||||
else
|
||||
{
|
||||
if (!IsSingle() && (Take != null || Skip != null))
|
||||
{
|
||||
var result = Regex.Replace(this.OrderByValue, @"\[\w+\]\.", "");
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.OrderByValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual string GetGroupByString
|
||||
{
|
||||
get
|
||||
|
||||
@@ -31,7 +31,8 @@ namespace SqlSugar
|
||||
{
|
||||
return _IsSingle;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
_IsSingle = value;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +121,10 @@ namespace SqlSugar
|
||||
public virtual string GetTranslationColumnName(string columnName)
|
||||
{
|
||||
Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "column Name"));
|
||||
if (columnName.Substring(0, 1) == this.SqlParameterKeyWord)
|
||||
{
|
||||
return columnName;
|
||||
}
|
||||
if (IsTranslationText(columnName)) return columnName;
|
||||
if (columnName.Contains("."))
|
||||
{
|
||||
@@ -159,17 +164,17 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual string GetAsString(string asName, string fieldValue)
|
||||
{
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationTableName(fieldValue), "AS", GetTranslationColumnName(asName));
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldValue), "AS", GetTranslationColumnName(asName));
|
||||
}
|
||||
|
||||
public virtual string GetEqString(string eqName, string fieldValue)
|
||||
{
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(eqName), "=", fieldValue);
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(eqName), "=", GetTranslationColumnName(fieldValue));
|
||||
}
|
||||
|
||||
public virtual string GetAsString(string asName, string fieldValue, string fieldShortName)
|
||||
{
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationTableName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName));
|
||||
return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName));
|
||||
}
|
||||
public virtual void Clear()
|
||||
{
|
||||
|
||||
@@ -191,6 +191,12 @@ namespace SqlSugar
|
||||
return string.Format(" CAST({0} AS DATETIME)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string ToTime(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS TIME)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public virtual string ToDecimal(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace SqlSugar
|
||||
string ToBool(MethodCallExpressionModel model);
|
||||
string Substring(MethodCallExpressionModel model);
|
||||
string ToDate(MethodCallExpressionModel model);
|
||||
string ToTime(MethodCallExpressionModel model);
|
||||
string ToDecimal(MethodCallExpressionModel model);
|
||||
string Length(MethodCallExpressionModel model);
|
||||
string Replace(MethodCallExpressionModel model);
|
||||
|
||||
@@ -69,7 +69,18 @@ namespace SqlSugar
|
||||
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static int ToInt32(object value) { return value.ObjToInt(); }
|
||||
public static long ToInt64(object value) { return Convert.ToInt64(value); }
|
||||
/// <summary>
|
||||
/// yyyy-MM-dd HH:mm:ss.fff
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ToDate(object value) { return value.ObjToDate(); }
|
||||
/// <summary>
|
||||
///HH:mm:ss
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static TimeSpan ToTime(object value) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static string ToString(object value) { return value.ObjToString(); }
|
||||
public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
|
||||
public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
|
||||
|
||||
@@ -106,7 +106,8 @@ namespace SqlSugar
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected void AppendMember(ExpressionParameter parameter, bool? isLeft, object appendValue) {
|
||||
protected void AppendMember(ExpressionParameter parameter, bool? isLeft, object appendValue)
|
||||
{
|
||||
|
||||
Context.ParameterIndex++;
|
||||
if (isLeft == true)
|
||||
@@ -215,13 +216,14 @@ namespace SqlSugar
|
||||
return methodCallExpressionArgs;
|
||||
}
|
||||
|
||||
protected void ResolveNewExpressions(ExpressionParameter parameter, int i, Expression item, string memberName)
|
||||
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string memberName)
|
||||
{
|
||||
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
@@ -231,7 +233,7 @@ namespace SqlSugar
|
||||
this.Start();
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
}
|
||||
else if (item is MemberExpression || item is UnaryExpression)
|
||||
else if (item is MemberExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
@@ -245,22 +247,70 @@ namespace SqlSugar
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item is BinaryExpression)
|
||||
else if (item is UnaryExpression && ((UnaryExpression)item).Operand is MemberExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
var expression = ((UnaryExpression)item).Operand as MemberExpression;
|
||||
if (expression.Expression == null)
|
||||
{
|
||||
this.Context.Result.CurrentParameter = parameter;
|
||||
this.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
this.Expression = item;
|
||||
parameter.CommonTempData = "simple";
|
||||
this.Start();
|
||||
parameter.CommonTempData = null;
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.TrimEnd();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
else if (expression.Expression is ConstantExpression)
|
||||
{
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.CurrentParameter = parameter;
|
||||
this.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item is UnaryExpression && ((UnaryExpression)item).Operand is ConstantExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
this.Expression = ((UnaryExpression)item).Operand;
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
}
|
||||
else if (item is BinaryExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
var newContext = this.Context.GetCopyContext();
|
||||
var resolveExpressType = this.Context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
|
||||
newContext.Resolve(item, resolveExpressType);
|
||||
this.Context.Index = newContext.Index;
|
||||
this.Context.ParameterIndex = newContext.ParameterIndex;
|
||||
if (newContext.Parameters.IsValuable())
|
||||
{
|
||||
this.Context.Parameters.AddRange(newContext.Parameters);
|
||||
}
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, newContext.Result.GetString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
{
|
||||
@@ -298,7 +348,6 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,6 @@ namespace SqlSugar
|
||||
public class BinaryExpressionResolve : BaseResolve
|
||||
{
|
||||
public BinaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||
{
|
||||
if (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals("simple"))
|
||||
{
|
||||
parameter.BaseParameter = parameter;
|
||||
new SimpleBinaryExpressionResolve(parameter);
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var expression = this.Expression as BinaryExpression;
|
||||
var operatorValue = parameter.OperatorValue = ExpressionTool.GetOperator(expression.NodeType);
|
||||
@@ -66,4 +58,3 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +87,8 @@ namespace SqlSugar
|
||||
|
||||
private void Select(MemberInitExpression expression, ExpressionParameter parameter, bool isSingle)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (MemberBinding binding in expression.Bindings)
|
||||
{
|
||||
++i;
|
||||
if (binding.BindingType != MemberBindingType.Assignment)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
@@ -98,7 +96,7 @@ namespace SqlSugar
|
||||
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
||||
var memberName = memberAssignment.Member.Name;
|
||||
var item = memberAssignment.Expression;
|
||||
ResolveNewExpressions(parameter, i, item, memberName);
|
||||
ResolveNewExpressions(parameter, item, memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +208,8 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.ToInt64(model);
|
||||
case "ToDate":
|
||||
return this.Context.DbMehtods.ToDate(model);
|
||||
case "ToTime":
|
||||
return this.Context.DbMehtods.ToTime(model);
|
||||
case "ToString":
|
||||
return this.Context.DbMehtods.ToString(model);
|
||||
case "ToDecimal":
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace SqlSugar
|
||||
{
|
||||
string memberName = expression.Members[i].Name;
|
||||
++i;
|
||||
ResolveNewExpressions(parameter, i, item, memberName);
|
||||
ResolveNewExpressions(parameter,item, memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,13 @@ namespace SqlSugar
|
||||
new ISugarQueryable<T, T2> GroupBy(Expression<Func<T, object>> expression);
|
||||
ISugarQueryable<T, T2> GroupBy(Expression<Func<T, T2, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T,T2, TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T,T2, TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T,T2, TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T,T2, TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -149,6 +156,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3> GroupBy(Expression<Func<T, T2, object>> expression);
|
||||
ISugarQueryable<T, T2, T3> GroupBy(Expression<Func<T, T2, T3, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2,T3, TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3, T4> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -186,6 +200,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4> GroupBy(Expression<Func<T, T2, T3, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4> GroupBy(Expression<Func<T, T2, T3, T4, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2, T3,T4,TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3, T4, T5> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -229,6 +250,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5> GroupBy(Expression<Func<T, T2, T3, T4, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5> GroupBy(Expression<Func<T, T2, T3, T4, T5, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4,T5,TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -276,6 +304,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> GroupBy(Expression<Func<T, T2, T3, T4, T5, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5,T6,TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -328,6 +363,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6,T7,TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> : ISugarQueryable<T>
|
||||
{
|
||||
@@ -385,6 +427,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> GroupBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object>> expression);
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
TResult Max<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
|
||||
TResult Min<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
|
||||
TResult Sum<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
|
||||
TResult Avg<TResult>(Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, TResult>> expression);
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@ using System.Runtime.InteropServices;
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")]
|
||||
[assembly: AssemblyVersion("4.1.1.2")]
|
||||
[assembly: AssemblyFileVersion("4.1.1.2")]
|
||||
[assembly: AssemblyVersion("4.1.1.5")]
|
||||
[assembly: AssemblyFileVersion("4.1.1.5")]
|
||||
|
||||
@@ -17,7 +17,12 @@ namespace SqlSugar
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
base._DbConnection = new MySqlConnection(base.Context.CurrentConnectionConfig.ConnectionString);
|
||||
var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
if (!mySqlConnectionString.ToLower().Contains("charset"))
|
||||
{
|
||||
mySqlConnectionString=mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;";
|
||||
}
|
||||
base._DbConnection = new MySqlConnection(mySqlConnectionString);
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,12 @@ namespace SqlSugar
|
||||
{
|
||||
public class SqlServerQueryBuilder: QueryBuilder
|
||||
{
|
||||
public override string SqlTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT {0}{{$:OrderByString:$}} FROM {1}{2}{3}{4}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>4.1.1.2</version>
|
||||
<version>4.1.1.5</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
||||
Reference in New Issue
Block a user