mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update Core
This commit is contained in:
parent
adf1309eee
commit
3b55625ba3
@ -35,37 +35,29 @@ namespace OrmTest.UnitTest
|
||||
var t2 = db.Queryable<Student>().With(SqlWith.NoLock).ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [STudent] WITH(NOLOCK)", null, t2.Key, null, "single t2 Error");
|
||||
|
||||
var t3 = db.Queryable<Student>().OrderBy(it=>it.Id).ToSql();
|
||||
var t3 = db.Queryable<Student>().OrderBy(it => it.Id).ToSql();
|
||||
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");
|
||||
var t6 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToSql();
|
||||
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) {
|
||||
int studentCount = db.Ado.GetInt("select count(1) from Student");
|
||||
var countIsSuccess = db.Queryable<Student>().Count() == studentCount;
|
||||
if (!countIsSuccess)
|
||||
{
|
||||
throw new Exception(" single countIsSuccess Error");
|
||||
}
|
||||
|
||||
var t7 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToPageList(pageIndex,pageSize,ref studentCount);
|
||||
var t7 = db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToPageList(pageIndex, pageSize, ref studentCount);
|
||||
countIsSuccess = studentCount == db.Queryable<Student>().OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize * pageIndex).Count();
|
||||
if (!countIsSuccess)
|
||||
{
|
||||
@ -73,7 +65,7 @@ namespace OrmTest.UnitTest
|
||||
}
|
||||
|
||||
int studentMin = db.Ado.GetInt("select min(id) from Student");
|
||||
var minIsSuccess = db.Queryable<Student>().Min(it=>it.Id) == studentMin;
|
||||
var minIsSuccess = db.Queryable<Student>().Min(it => it.Id) == studentMin;
|
||||
if (!minIsSuccess)
|
||||
{
|
||||
throw new Exception("single minIsSuccess Error");
|
||||
@ -101,23 +93,20 @@ namespace OrmTest.UnitTest
|
||||
}
|
||||
|
||||
var t8 = db.Queryable<Student>()
|
||||
.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>() {
|
||||
.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(@"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");
|
||||
}, t8.Key, t8.Value, "single t8 Error");
|
||||
|
||||
|
||||
|
||||
var t9 = db.Queryable<Student>()
|
||||
.In(1)
|
||||
.Select(it => new { it.Id, it.Name,x=it.Id }).ToSql();
|
||||
.Select(it => new { it.Id, it.Name, x = it.Id }).ToSql();
|
||||
base.Check("SELECT [ID] AS [Id] , [Name] AS [Name] , [ID] AS [x] FROM [STudent] WHERE [Id] IN (@InPara0) ", new List<SugarParameter>() {
|
||||
new SugarParameter("@InPara0",1) },t9.Key,t9.Value, "single t9 error");
|
||||
new SugarParameter("@InPara0",1) }, t9.Key, t9.Value, "single t9 error");
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +114,7 @@ namespace OrmTest.UnitTest
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer });
|
||||
return db;
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -123,7 +123,7 @@ namespace SqlSugar
|
||||
public virtual ISugarQueryable<T> Where<T2>(string whereString, object whereObj = null)
|
||||
{
|
||||
var whereValue = QueryBuilder.WhereInfos;
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString+PubConst.Space));
|
||||
whereValue.Add(SqlBuilder.AppendWhereOrAnd(whereValue.Count == 0, whereString + PubConst.Space));
|
||||
if (whereObj != null)
|
||||
QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(whereObj));
|
||||
return this;
|
||||
@ -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,7 +489,10 @@ namespace SqlSugar
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
totalNumber = this.Count();
|
||||
return ToPageList(pageIndex, pageSize);
|
||||
if (totalNumber == 0)
|
||||
return new List<T>();
|
||||
else
|
||||
return ToPageList(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
@ -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;
|
||||
@ -677,7 +698,7 @@ namespace SqlSugar
|
||||
_Where(expression);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
@ -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
|
||||
@ -807,27 +847,27 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3> WhereIF(bool isWhere,Expression<Func<T, T2, bool>> expression)
|
||||
public ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
if (isWhere)
|
||||
_Where(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, Expression<Func<T, bool>> expression)
|
||||
public new ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, Expression<Func<T, bool>> expression)
|
||||
{
|
||||
if (isWhere)
|
||||
_Where(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2,T3> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2,T3> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
@ -890,13 +948,13 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3,T4> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3,T4> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
@ -1031,13 +1108,13 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4,T5> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4,T5> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
@ -1198,13 +1294,13 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
@ -1342,7 +1457,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIF(bool isWhere, Expression<Func<T, bool>> expression)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIF(bool isWhere, Expression<Func<T, bool>> expression)
|
||||
{
|
||||
if (isWhere)
|
||||
_Where(expression);
|
||||
@ -1391,13 +1506,13 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
@ -1611,13 +1745,13 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> Where(string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Where(string whereString, object whereObj)
|
||||
{
|
||||
Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIF(bool isWhere, string whereString, object whereObj)
|
||||
{
|
||||
if (!isWhere) return this;
|
||||
this.Where<T>(whereString, whereObj);
|
||||
@ -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
|
||||
{
|
||||
@ -406,15 +396,7 @@ namespace SqlSugar
|
||||
if (IsCount) return null;
|
||||
else
|
||||
{
|
||||
if (!IsSingle() && (Take != null || Skip != null))
|
||||
{
|
||||
var result = Regex.Replace(this.OrderByValue, @"\[\w+\]\.", "");
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.OrderByValue;
|
||||
}
|
||||
return this.OrderByValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace SqlSugar
|
||||
public class ExpressionContext : ExpResolveAccessory
|
||||
{
|
||||
#region Fields
|
||||
private bool _IsSingle = true;
|
||||
private bool _IsSingle = true;
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
@ -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)
|
||||
@ -200,7 +201,7 @@ namespace SqlSugar
|
||||
protected MethodCallExpressionArgs GetMethodCallArgs(ExpressionParameter parameter, Expression item)
|
||||
{
|
||||
var newContext = this.Context.GetCopyContext();
|
||||
newContext.Resolve(item, this.Context.IsJoin?ResolveExpressType.WhereMultiple:ResolveExpressType.WhereSingle);
|
||||
newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle);
|
||||
this.Context.Index = newContext.Index;
|
||||
this.Context.ParameterIndex = newContext.ParameterIndex;
|
||||
if (newContext.Parameters.IsValuable())
|
||||
@ -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,20 +247,68 @@ namespace SqlSugar
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
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;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
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)
|
||||
{
|
||||
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()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -282,7 +332,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
var asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name );
|
||||
var asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
@ -298,7 +348,6 @@ namespace SqlSugar
|
||||
else
|
||||
{
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,60 +9,51 @@ namespace SqlSugar
|
||||
{
|
||||
public BinaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
|
||||
{
|
||||
if (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals("simple"))
|
||||
var expression = this.Expression as BinaryExpression;
|
||||
var operatorValue = parameter.OperatorValue = ExpressionTool.GetOperator(expression.NodeType);
|
||||
var isEqual = expression.NodeType == ExpressionType.Equal;
|
||||
var isComparisonOperator = ExpressionTool.IsComparisonOperator(expression);
|
||||
base.ExactExpression = expression;
|
||||
var leftExpression = expression.Left;
|
||||
var rightExpression = expression.Right;
|
||||
var leftIsBinary = leftExpression is BinaryExpression;
|
||||
var rightBinary = rightExpression is BinaryExpression;
|
||||
var lbrs = leftIsBinary && !rightBinary;
|
||||
var lsrb = !leftIsBinary && rightBinary;
|
||||
var lbrb = rightBinary && leftIsBinary;
|
||||
var lsbs = !leftIsBinary && !rightBinary;
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.Format0);
|
||||
if (isAppend)
|
||||
{
|
||||
parameter.BaseParameter = parameter;
|
||||
new SimpleBinaryExpressionResolve(parameter);
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
base.Context.Result.Append(ExpressionConst.Format3);
|
||||
base.Context.Result.Append(ExpressionConst.Format0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var expression = this.Expression as BinaryExpression;
|
||||
var operatorValue = parameter.OperatorValue = ExpressionTool.GetOperator(expression.NodeType);
|
||||
var isEqual = expression.NodeType == ExpressionType.Equal;
|
||||
var isComparisonOperator =ExpressionTool.IsComparisonOperator(expression);
|
||||
base.ExactExpression = expression;
|
||||
var leftExpression = expression.Left;
|
||||
var rightExpression = expression.Right;
|
||||
var leftIsBinary = leftExpression is BinaryExpression;
|
||||
var rightBinary = rightExpression is BinaryExpression;
|
||||
var lbrs = leftIsBinary && !rightBinary;
|
||||
var lsrb = !leftIsBinary && rightBinary;
|
||||
var lbrb = rightBinary && leftIsBinary;
|
||||
var lsbs = !leftIsBinary && !rightBinary;
|
||||
var isAppend = !base.Context.Result.Contains(ExpressionConst.Format0);
|
||||
if (isAppend)
|
||||
{
|
||||
base.Context.Result.Append(ExpressionConst.Format3);
|
||||
base.Context.Result.Append(ExpressionConst.Format0);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, ExpressionConst.Format3 + ExpressionConst.Format0);
|
||||
}
|
||||
parameter.LeftExpression = leftExpression;
|
||||
parameter.RightExpression = rightExpression;
|
||||
base.Expression = leftExpression;
|
||||
base.IsLeft = true;
|
||||
base.Start();
|
||||
base.IsLeft = false;
|
||||
base.Expression = rightExpression;
|
||||
base.Start();
|
||||
base.IsLeft = null;
|
||||
if (lsbs && parameter.ValueIsNull)
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index + 1), operatorValue);
|
||||
}
|
||||
base.Context.Result.Append(ExpressionConst.Format4);
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true)
|
||||
{
|
||||
base.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index + " ");
|
||||
}
|
||||
base.Context.Result.Replace(ExpressionConst.Format0, ExpressionConst.Format3 + ExpressionConst.Format0);
|
||||
}
|
||||
parameter.LeftExpression = leftExpression;
|
||||
parameter.RightExpression = rightExpression;
|
||||
base.Expression = leftExpression;
|
||||
base.IsLeft = true;
|
||||
base.Start();
|
||||
base.IsLeft = false;
|
||||
base.Expression = rightExpression;
|
||||
base.Start();
|
||||
base.IsLeft = null;
|
||||
if (lsbs && parameter.ValueIsNull)
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, isEqual ? "IS" : "IS NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, operatorValue);
|
||||
base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index + 1), operatorValue);
|
||||
}
|
||||
base.Context.Result.Append(ExpressionConst.Format4);
|
||||
if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true)
|
||||
{
|
||||
base.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user