Update Core

This commit is contained in:
sunkaixuan
2019-04-28 16:08:45 +08:00
parent d0027bfbda
commit ff5af85b03
23 changed files with 660 additions and 70 deletions

View File

@@ -365,6 +365,9 @@ namespace SqlSugar
var convertString = GetProertypeDefaultValue(item);
if (convertString == "DateTime.Now" || convertString == null)
return convertString;
if (convertString.ObjToString() == "newid()") {
return "Guid.NewGuid()";
}
if (item.DataType == "bit")
return (convertString == "1" || convertString.Equals("true",StringComparison.CurrentCultureIgnoreCase)).ToString().ToLower();
string result = this.Context.Ado.DbBind.GetConvertString(item.DataType) + "(\"" + convertString + "\")";

View File

@@ -50,36 +50,36 @@ namespace SqlSugar
return _exp;
}
}
public class Expressionable<T,T2> where T : class, new() where T2 : class, new()
public class Expressionable<T, T2> where T : class, new() where T2 : class, new()
{
Expression<Func<T,T2, bool>> _exp = null;
Expression<Func<T, T2, bool>> _exp = null;
public Expressionable<T,T2> And(Expression<Func<T,T2, bool>> exp)
public Expressionable<T, T2> And(Expression<Func<T, T2, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T,T2, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T,T2> AndIF(bool isAnd, Expression<Func<T,T2, bool>> exp)
public Expressionable<T, T2> AndIF(bool isAnd, Expression<Func<T, T2, bool>> exp)
{
if (isAnd)
And(exp);
return this;
}
public Expressionable<T,T2> Or(Expression<Func<T,T2, bool>> exp)
public Expressionable<T, T2> Or(Expression<Func<T, T2, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T,T2, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T,T2> OrIF(bool isOr, Expression<Func<T,T2, bool>> exp)
public Expressionable<T, T2> OrIF(bool isOr, Expression<Func<T, T2, bool>> exp)
{
if (isOr)
Or(exp);
@@ -87,43 +87,43 @@ namespace SqlSugar
}
public Expression<Func<T,T2, bool>> ToExpression()
public Expression<Func<T, T2, bool>> ToExpression()
{
if (_exp == null)
_exp = (it,t2) => true;
_exp = (it, t2) => true;
return _exp;
}
}
public class Expressionable<T, T2,T3> where T : class, new() where T2 : class, new() where T3 : class, new()
public class Expressionable<T, T2, T3> where T : class, new() where T2 : class, new() where T3 : class, new()
{
Expression<Func<T, T2,T3, bool>> _exp = null;
Expression<Func<T, T2, T3, bool>> _exp = null;
public Expressionable<T, T2,T3> And(Expression<Func<T, T2,T3, bool>> exp)
public Expressionable<T, T2, T3> And(Expression<Func<T, T2, T3, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2,T3, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2,T3> AndIF(bool isAnd, Expression<Func<T, T2,T3, bool>> exp)
public Expressionable<T, T2, T3> AndIF(bool isAnd, Expression<Func<T, T2, T3, bool>> exp)
{
if (isAnd)
And(exp);
return this;
}
public Expressionable<T, T2,T3> Or(Expression<Func<T, T2,T3, bool>> exp)
public Expressionable<T, T2, T3> Or(Expression<Func<T, T2, T3, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2,T3, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2,T3> OrIF(bool isOr, Expression<Func<T, T2,T3, bool>> exp)
public Expressionable<T, T2, T3> OrIF(bool isOr, Expression<Func<T, T2, T3, bool>> exp)
{
if (isOr)
Or(exp);
@@ -131,43 +131,43 @@ namespace SqlSugar
}
public Expression<Func<T, T2,T3, bool>> ToExpression()
public Expression<Func<T, T2, T3, bool>> ToExpression()
{
if (_exp == null)
_exp = (it, t2,t3) => true;
_exp = (it, t2, t3) => true;
return _exp;
}
}
public class Expressionable<T, T2, T3,T4> where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new()
public class Expressionable<T, T2, T3, T4> where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new()
{
Expression<Func<T, T2, T3,T4, bool>> _exp = null;
Expression<Func<T, T2, T3, T4, bool>> _exp = null;
public Expressionable<T, T2, T3,T4> And(Expression<Func<T, T2, T3,T4, bool>> exp)
public Expressionable<T, T2, T3, T4> And(Expression<Func<T, T2, T3, T4, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3,T4, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, T4, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3,T4> AndIF(bool isAnd, Expression<Func<T, T2, T3,T4, bool>> exp)
public Expressionable<T, T2, T3, T4> AndIF(bool isAnd, Expression<Func<T, T2, T3, T4, bool>> exp)
{
if (isAnd)
And(exp);
return this;
}
public Expressionable<T, T2, T3,T4> Or(Expression<Func<T, T2, T3,T4, bool>> exp)
public Expressionable<T, T2, T3, T4> Or(Expression<Func<T, T2, T3, T4, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3,T4, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, T4, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3,T4> OrIF(bool isOr, Expression<Func<T, T2, T3,T4, bool>> exp)
public Expressionable<T, T2, T3, T4> OrIF(bool isOr, Expression<Func<T, T2, T3, T4, bool>> exp)
{
if (isOr)
Or(exp);
@@ -175,43 +175,43 @@ namespace SqlSugar
}
public Expression<Func<T, T2, T3,T4, bool>> ToExpression()
public Expression<Func<T, T2, T3, T4, bool>> ToExpression()
{
if (_exp == null)
_exp = (it, t2, t3,t4) => true;
_exp = (it, t2, t3, t4) => true;
return _exp;
}
}
public class Expressionable<T, T2, T3, T4,T5> where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5: class,new()
public class Expressionable<T, T2, T3, T4, T5> where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new()
{
Expression<Func<T, T2, T3, T4,T5, bool>> _exp = null;
Expression<Func<T, T2, T3, T4, T5, bool>> _exp = null;
public Expressionable<T, T2, T3, T4,T5> And(Expression<Func<T, T2, T3, T4,T5, bool>> exp)
public Expressionable<T, T2, T3, T4, T5> And(Expression<Func<T, T2, T3, T4, T5, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3, T4,T5, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, T4, T5, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3, T4,T5> AndIF(bool isAnd, Expression<Func<T, T2, T3, T4,T5, bool>> exp)
public Expressionable<T, T2, T3, T4, T5> AndIF(bool isAnd, Expression<Func<T, T2, T3, T4, T5, bool>> exp)
{
if (isAnd)
And(exp);
return this;
}
public Expressionable<T, T2, T3, T4,T5> Or(Expression<Func<T, T2, T3, T4,T5, bool>> exp)
public Expressionable<T, T2, T3, T4, T5> Or(Expression<Func<T, T2, T3, T4, T5, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3, T4,T5, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
_exp = Expression.Lambda<Func<T, T2, T3, T4, T5, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3, T4,T5> OrIF(bool isOr, Expression<Func<T, T2, T3, T4,T5, bool>> exp)
public Expressionable<T, T2, T3, T4, T5> OrIF(bool isOr, Expression<Func<T, T2, T3, T4, T5, bool>> exp)
{
if (isOr)
Or(exp);
@@ -219,35 +219,83 @@ namespace SqlSugar
}
public Expression<Func<T, T2, T3, T4,T5, bool>> ToExpression()
public Expression<Func<T, T2, T3, T4, T5, bool>> ToExpression()
{
if (_exp == null)
_exp = (it, t2, t3, t4,T5) => true;
_exp = (it, t2, t3, t4, T5) => true;
return _exp;
}
}
public class Expressionable<T, T2, T3, T4, T5, T6> where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new()
{
Expression<Func<T, T2, T3, T4, T5, T6, bool>> _exp = null;
public Expressionable<T, T2, T3, T4, T5, T6> And(Expression<Func<T, T2, T3, T4, T5, T6, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3, T4, T5, T6, bool>>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3, T4, T5, T6> AndIF(bool isAnd, Expression<Func<T, T2, T3, T4, T5, T6, bool>> exp)
{
if (isAnd)
And(exp);
return this;
}
public Expressionable<T, T2, T3, T4, T5, T6> Or(Expression<Func<T, T2, T3, T4, T5, T6, bool>> exp)
{
if (_exp == null)
_exp = exp;
else
_exp = Expression.Lambda<Func<T, T2, T3, T4, T5, T6, bool>>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters);
return this;
}
public Expressionable<T, T2, T3, T4, T5, T6> OrIF(bool isOr, Expression<Func<T, T2, T3, T4, T5, T6, bool>> exp)
{
if (isOr)
Or(exp);
return this;
}
public Expression<Func<T, T2, T3, T4, T5, T6, bool>> ToExpression()
{
if (_exp == null)
_exp = (it, t2, t3, t4, T5, t6) => true;
return _exp;
}
}
public class Expressionable
{
public static Expressionable<T> Create<T>() where T : class, new()
{
return new Expressionable<T>();
}
public static Expressionable<T,T2> Create<T,T2>() where T : class, new() where T2 : class, new()
public static Expressionable<T, T2> Create<T, T2>() where T : class, new() where T2 : class, new()
{
return new Expressionable<T,T2>();
return new Expressionable<T, T2>();
}
public static Expressionable<T, T2,T3> Create<T, T2,T3>() where T : class, new() where T2 : class, new() where T3 : class, new()
public static Expressionable<T, T2, T3> Create<T, T2, T3>() where T : class, new() where T2 : class, new() where T3 : class, new()
{
return new Expressionable<T, T2,T3>();
return new Expressionable<T, T2, T3>();
}
public static Expressionable<T, T2, T3,T4> Create<T, T2, T3,T4>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4: class, new()
public static Expressionable<T, T2, T3, T4> Create<T, T2, T3, T4>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new()
{
return new Expressionable<T, T2, T3,T4>();
return new Expressionable<T, T2, T3, T4>();
}
public static Expressionable<T, T2, T3, T4,T5> Create<T, T2, T3, T4,T5>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5:class,new()
public static Expressionable<T, T2, T3, T4, T5> Create<T, T2, T3, T4, T5>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new()
{
return new Expressionable<T, T2, T3, T4,T5>();
return new Expressionable<T, T2, T3, T4, T5>();
}
public static Expressionable<T, T2, T3, T4, T5, T6> Create<T, T2, T3, T4, T5, T6>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new()
{
return new Expressionable<T, T2, T3, T4, T5, T6>();
}
}
}

View File

@@ -727,6 +727,12 @@ namespace SqlSugar
var result = ToDataTablePage(pageIndex, pageSize);
return result;
}
public virtual DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage)
{
var result = ToDataTablePage(pageIndex, pageSize, ref totalNumber);
totalPage = (totalNumber + pageSize - 1) / pageSize;
return result;
}
public virtual List<T> ToList()
{
@@ -767,6 +773,12 @@ namespace SqlSugar
totalNumber = count;
return result;
}
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber, ref int totalPage)
{
var result = ToPageList(pageIndex, pageSize, ref totalNumber);
totalPage = (totalNumber + pageSize - 1) / pageSize;
return result;
}
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
{
@@ -778,13 +790,16 @@ namespace SqlSugar
}
public ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
Check.ArgumentNullException(this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService, "Use Cache ConnectionConfig.ConfigureExternalServices.DataInfoCacheService is required ");
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (isCache)
{
this.IsCache = true;
@@ -1631,6 +1646,15 @@ namespace SqlSugar
asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos;
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
}
protected int SetCacheTime(int cacheDurationInSeconds)
{
if (cacheDurationInSeconds == int.MaxValue && this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds > 0)
{
cacheDurationInSeconds = this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds;
}
return cacheDurationInSeconds;
}
#endregion
}
@@ -1912,12 +1936,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (isCache)
{
this.IsCache = true;
@@ -2281,12 +2307,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -2708,12 +2736,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -3062,12 +3092,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -3447,12 +3479,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -3863,12 +3897,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -4312,12 +4348,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -4710,12 +4748,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -5119,12 +5159,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -5552,12 +5594,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;
@@ -6011,12 +6055,14 @@ namespace SqlSugar
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCache(int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
this.IsCache = true;
this.CacheTime = cacheDurationInSeconds;
return this;
}
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue)
{
cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds);
if (IsCache)
{
this.IsCache = true;

View File

@@ -189,7 +189,7 @@ namespace SqlSugar
{
var isFirst = whereString == null;
whereString += (isFirst ? null : " AND ");
whereString += Regex.Replace(item,"\\"+this.Builder.SqlTranslationLeft,"T."+ this.Builder.SqlTranslationLeft);
whereString += Regex.Replace(item,"\\"+this.Builder.SqlTranslationLeft,"S."+ this.Builder.SqlTranslationLeft);
}
}
if (PrimaryKeys.HasValue())

View File

@@ -13,5 +13,6 @@ namespace SqlSugar
/// Some MYSQL databases do not support NVarchar set true
/// </summary>
public bool MySqlDisableNarvchar { get; set; }
public int DefaultCacheDurationInSeconds { get; set; }
}
}

View File

@@ -1,16 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class JoinQueryInfo
{
public JoinType JoinType{ get; set; }
public JoinType JoinType { get; set; }
public string TableName { get; set; }
public string ShortName { get; set; }
public int JoinIndex { get; set; }
public string JoinWhere { get; set; }
}
public class JoinQueryInfos
{
private JoinQueryInfos() { }
public JoinQueryInfos(JoinType joinType, bool whereExpress)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6, JoinType joinType7, bool whereExpress7)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6, JoinType joinType7, bool whereExpress7, JoinType joinType8, bool whereExpress8)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6, JoinType joinType7, bool whereExpress7, JoinType joinType8, bool whereExpress8, JoinType joinType9, bool whereExpress9)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6, JoinType joinType7, bool whereExpress7, JoinType joinType8, bool whereExpress8, JoinType joinType9, bool whereExpress9, JoinType joinType10, bool whereExpress10)
{
}
public JoinQueryInfos(JoinType joinType, bool whereExpress, JoinType joinType2, bool whereExpress2, JoinType joinType3, bool whereExpress3, JoinType joinType4, bool whereExpress4, JoinType joinType5, bool whereExpress5, JoinType joinType6, bool whereExpress6, JoinType joinType7, bool whereExpress7, JoinType joinType8, bool whereExpress8, JoinType joinType9, bool whereExpress9, JoinType joinType10, bool whereExpress10, JoinType joinType11, bool whereExpress11)
{
}
}
}

View File

@@ -128,6 +128,19 @@ namespace SqlSugar
set { _IsTranscoding = value; }
}
private bool _NoSerialize;
public bool NoSerialize
{
get { return _NoSerialize; }
set { _NoSerialize = value; }
}
private string _SerializeDateTimeFormat;
public string SerializeDateTimeFormat
{
get { return _SerializeDateTimeFormat; }
set { _SerializeDateTimeFormat = value; }
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public partial class SugarDateTimeFormat
{
public const string Default = "yyyy-MM-dd HH:mm:ss";
public const string Date = "yyyy-MM-dd HH";
}
}

View File

@@ -255,5 +255,10 @@ namespace SqlSugar
{
return !IsEntity(type);
}
public static bool IsUnConvertExpress(Expression item)
{
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
}
}
}

View File

@@ -9,6 +9,7 @@ namespace SqlSugar
public class MethodCallExpressionModel
{
public List<MethodCallExpressionArgs> Args { get; set; }
public string Name { get; internal set; }
}
public class MethodCallExpressionArgs

View File

@@ -41,6 +41,35 @@ namespace SqlSugar
SettingDataType(type);
}
public SugarParameter(string name, object value, System.Data.DbType type)
{
this.Value = value;
this.ParameterName = name;
this.DbType = type;
}
public SugarParameter(string name, DataTable value,string SqlServerTypeName)
{
this.Value = value;
this.ParameterName = name;
this.TypeName = SqlServerTypeName;
}
public SugarParameter(string name, object value, System.Data.DbType type, ParameterDirection direction)
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
this.DbType = type;
}
public SugarParameter(string name, object value, System.Data.DbType type, ParameterDirection direction, int size)
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
this.Size = size;
this.DbType = type;
}
private void SettingDataType(Type type)
{
if (type == UtilConstants.ByteArrayType)
@@ -197,5 +226,8 @@ namespace SqlSugar
{
this.DbType = System.Data.DbType.String;
}
public string TypeName { get; set; }
}
}

View File

@@ -342,7 +342,7 @@ namespace SqlSugar
{
var expression = ((UnaryExpression)item).Operand as MemberExpression;
var isDateTimeNow = ((UnaryExpression)item).Operand.ToString() == "DateTime.Now";
if (expression.Expression == null&&!isDateTimeNow)
if (expression.Expression == null && !isDateTimeNow)
{
this.Context.Result.CurrentParameter = parameter;
this.Context.Result.IsLockCurrentParameter = true;
@@ -353,7 +353,7 @@ namespace SqlSugar
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
this.Context.Result.CurrentParameter = null;
}
else if (expression.Expression is ConstantExpression||isDateTimeNow)
else if (expression.Expression is ConstantExpression || isDateTimeNow)
{
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
this.Context.ParameterIndex++;
@@ -400,7 +400,8 @@ namespace SqlSugar
}
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
this.Context.Result.CurrentParameter = null;
if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue()) {
if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue())
{
this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
}
}
@@ -427,7 +428,8 @@ namespace SqlSugar
var propertyName = property.Name;
var dbColumnName = propertyName;
var mappingInfo = this.Context.MappingColumns.FirstOrDefault(it => it.EntityName == item.Type.Name && it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo.HasValue()) {
if (mappingInfo.HasValue())
{
dbColumnName = mappingInfo.DbColumnName;
}
asName = this.Context.GetTranslationText(item.Type.Name + "." + propertyName);
@@ -442,7 +444,30 @@ namespace SqlSugar
}
}
}
else if (item is MethodCallExpression|| item is UnaryExpression||item is ConditionalExpression|| item.NodeType==ExpressionType.Coalesce)
else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression && (item as MethodCallExpression).Method.Name == "Any"&&IsSubMethod(item as MethodCallExpression))
{
this.Expression = item;
this.Start();
var sql= this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
{
Args=new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs() {
IsMember=true,
MemberName=parameter.CommonTempData.ObjToString()
},
new MethodCallExpressionArgs() {
IsMember=true,
MemberName=1
},
new MethodCallExpressionArgs() {
IsMember=true,
MemberName=0
}
}
});
parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
}
else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
{
this.Expression = item;
this.Start();
@@ -453,6 +478,11 @@ namespace SqlSugar
Check.ThrowNotSupportedException(item.GetType().Name);
}
}
protected bool IsSubMethod(MethodCallExpression express)
{
return SubTools.SubItemsConst.Any(it => express.Object != null && express.Object.Type.Name == "Subqueryable`1");
}
protected static Dictionary<string, string> MethodMapping = new Dictionary<string, string>() {
{ "ToString","ToString"},
{ "ToInt32","ToInt32"},

View File

@@ -172,6 +172,7 @@ namespace SqlSugar
var method = express.Method;
var args = express.Arguments.Cast<Expression>().ToList();
MethodCallExpressionModel model = new MethodCallExpressionModel();
model.Name = name;
model.Args = new List<MethodCallExpressionArgs>();
switch (this.Context.ResolveType)
{
@@ -297,6 +298,10 @@ namespace SqlSugar
private void AppendItem(ExpressionParameter parameter, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, Expression item)
{
if (ExpressionTool.IsUnConvertExpress(item))
{
item = (item as UnaryExpression).Operand;
}
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
var isConst = item is ConstantExpression;
var isIIF = name == "IIF";
@@ -343,6 +348,8 @@ namespace SqlSugar
AppendModel(parameter, model, item);
}
}
private void AppendModelByIIFMember(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
{
parameter.CommonTempData = CommonTempDataType.Result;
@@ -401,7 +408,12 @@ namespace SqlSugar
{
parameter.CommonTempData = DateTime.Now.Date;
}
else {
else if (model.Name == "ToString"&&item is ConstantExpression&&(item as ConstantExpression).Type.IsEnum())
{
parameter.CommonTempData = item.ToString();
}
else
{
base.Start();
}
var methodCallExpressionArgs = new MethodCallExpressionArgs()

View File

@@ -23,7 +23,7 @@ namespace SqlSugar
Check.ThrowNotSupportedException(expression.ToString());
break;
case ResolveExpressType.SelectSingle:
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ",expression.ToString());
Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
Select(expression, parameter, true);
break;
case ResolveExpressType.SelectMultiple:
@@ -42,6 +42,30 @@ namespace SqlSugar
base.Start();
}
break;
case ResolveExpressType.Join:
base.Context.ResolveType = ResolveExpressType.WhereMultiple;
int i = 0;
foreach (var item in expression.Arguments)
{
if (item.Type!=typeof(JoinType))
{
base.Expression = item;
base.Start();
}
if (item.Type == typeof(JoinType))
{
if (i > 0)
{
base.Context.Result.Append("," + item.ToString()+ ",");
}
else
{
base.Context.Result.Append(item.ToString() + ",");
}
++i;
}
}
break;
default:
break;
}

View File

@@ -40,7 +40,12 @@ namespace SqlSugar
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
var type = ResolveExpressType.FieldSingle;
if ((argExp as LambdaExpression).Body is NewExpression) {
type = ResolveExpressType.ArraySingle;
}
var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp,type);
result = result.TrimEnd(',');
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
return result;

View File

@@ -39,12 +39,16 @@ namespace SqlSugar
}
else if (context.Expression is MethodCallExpression)
{
var meExp = ((context.Expression as MethodCallExpression).Object as MethodCallExpression).Arguments[0] as LambdaExpression;
var selfParameterName = meExp.Parameters.First().Name;
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression).Expression as ParameterExpression).Name;
if (context.SingleTableNameSubqueryShortName == selfParameterName)
var expArgs = ((context.Expression as MethodCallExpression).Object as MethodCallExpression).Arguments;
if (expArgs != null && expArgs.Any())
{
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
var meExp = expArgs[0] as LambdaExpression;
var selfParameterName = meExp.Parameters.First().Name;
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression).Expression as ParameterExpression).Name;
if (context.SingleTableNameSubqueryShortName == selfParameterName)
{
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
}
}
}
else if (context.Expression.GetType().Name == "MethodBinaryExpression")

View File

@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -6,17 +8,63 @@ using System.Text;
namespace SqlSugar
{
public class SerializeService:ISerializeService
public class SerializeService : ISerializeService
{
public string SerializeObject(object value)
{
return JsonConvert.SerializeObject(value);
return JsonConvert.SerializeObject(value, new JsonSerializerSettings()
{
ContractResolver = new MyContractResolver()
});
}
public T DeserializeObject<T>(string value)
{
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new MyContractResolver() };
return JsonConvert.DeserializeObject<T>(value, jSetting);
}
}
public class MyContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
{
public MyContractResolver()
{
}
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var list = type.GetProperties()
.Where(x => !x.GetCustomAttributes(true).Any(a => (a is SugarColumn) && ((SugarColumn)a).NoSerialize == true))
.Select(p => new JsonProperty()
{
PropertyName = p.Name,
PropertyType = p.PropertyType,
Readable = true,
Writable = true,
ValueProvider = base.CreateMemberValueProvider(p)
}).ToList();
foreach (var item in list)
{
if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.DateType)
{
CreateDateProperty(type, item);
}
}
return list;
}
private static void CreateDateProperty(Type type, JsonProperty item)
{
var property = type.GetProperties().Where(it => it.Name == item.PropertyName).First();
var itemType = UtilMethods.GetUnderType(property);
if (property.GetCustomAttributes(true).Any(it => it is SugarColumn))
{
var sugarAttribute = (SugarColumn)property.GetCustomAttributes(true).First(it => it is SugarColumn);
item.Converter = new IsoDateTimeConverter() { DateTimeFormat = sugarAttribute.SerializeDateTimeFormat };
}
}
}
}

View File

@@ -136,11 +136,13 @@ namespace SqlSugar
DataTable ToDataTablePage(int pageIndex, int pageSize);
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize);
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber);
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
Task<KeyValuePair<DataTable, int>> ToDataTablePageAsync(int pageIndex, int pageSize, int totalNumber);
List<T> ToPageList(int pageIndex, int pageSize);
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize);
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber);
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
Task<KeyValuePair<List<T>, int>> ToPageListAsync(int pageIndex, int pageSize, int totalNumber);
ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue);
ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue);

View File

@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace SqlSugar
{
public interface ISqlSugarClient
{
IAdo Ado { get; }
AopProvider Aop { get; }
ICodeFirst CodeFirst { get; }
SqlSugarClient Context { get; set; }
Guid ContextID { get; set; }
ConnectionConfig CurrentConnectionConfig { get; set; }
IDbFirst DbFirst { get; }
IDbMaintenance DbMaintenance { get; }
EntityMaintenance EntityMaintenance { get; set; }
EntityMaintenance EntityProvider { get; set; }
bool IsSystemTablesConfig { get; }
QueryFilterProvider QueryFilter { get; set; }
IContextMethods RewritableMethods { get; set; }
SimpleClient SimpleClient { get; }
Dictionary<string, object> TempItems { get; set; }
IContextMethods Utilities { get; set; }
void AddQueue(string sql, SugarParameter parsmeter);
void AddQueue(string sql, List<SugarParameter> parsmeters);
void AddQueue(string sql, object parsmeters = null);
void Close();
IDeleteable<T> Deleteable<T>() where T : class, new();
IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new();
IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new();
IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new();
IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new();
IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new();
IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new();
void Dispose();
DateTime GetDate();
SimpleClient GetSimpleClient();
SimpleClient<T> GetSimpleClient<T>() where T : class, new();
void InitMppingInfo(Type type);
IInsertable<T> Insertable<T>(T[] insertObjs) where T : class, new();
IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new();
IInsertable<T> Insertable<T>(T insertObj) where T : class, new();
IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new();
IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new();
void Open();
ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName);
ISugarQueryable<T> Queryable<T>();
ISugarQueryable<T> Queryable<T>(string shortName);
ISugarQueryable<T> Queryable<T>(ISugarQueryable<T> queryable) where T : class, new();
ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, object[]>> joinExpression);
ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2> Queryable<T, T2>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, Expression<Func<T, T2, bool>> joinExpression)
where T : class, new()
where T2 : class, new();
ISugarQueryable<T, T2> Queryable<T, T2>(ISugarQueryable<T> joinQueryable1, ISugarQueryable<T2> joinQueryable2, JoinType joinType, Expression<Func<T, T2, bool>> joinExpression)
where T : class, new()
where T2 : class, new();
ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression);
ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> joinExpression) where T : class, new();
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, JoinQueryInfos>> joinExpression);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> joinExpression) where T : class, new();
ISaveable<T> Saveable<T>(T saveObject) where T : class, new();
ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new();
int SaveQueues(bool isTran = true);
List<T> SaveQueues<T>(bool isTran = true);
Tuple<List<T>, List<T2>> SaveQueues<T, T2>(bool isTran = true);
Tuple<List<T>, List<T2>, List<T3>> SaveQueues<T, T2, T3>(bool isTran = true);
Tuple<List<T>, List<T2>, List<T3>, List<T4>> SaveQueues<T, T2, T3, T4>(bool isTran = true);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SaveQueues<T, T2, T3, T4, T5>(bool isTran = true);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SaveQueues<T, T2, T3, T4, T5, T6>(bool isTran = true);
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SaveQueues<T, T2, T3, T4, T5, T6, T7>(bool isTran = true);
Task<int> SaveQueuesAsync(bool isTran = true);
Task<List<T>> SaveQueuesAsync<T>(bool isTran = true);
Task<Tuple<List<T>, List<T2>>> SaveQueuesAsync<T, T2>(bool isTran = true);
Task<Tuple<List<T>, List<T2>, List<T3>>> SaveQueuesAsync<T, T2, T3>(bool isTran = true);
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SaveQueuesAsync<T, T2, T3, T4>(bool isTran = true);
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SaveQueuesAsync<T, T2, T3, T4, T5>(bool isTran = true);
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6>(bool isTran = true);
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6, T7>(bool isTran = true);
ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new();
ISugarQueryable<T> Union<T>(params ISugarQueryable<T>[] queryables) where T : class, new();
ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new();
ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new();
ISugarQueryable<T> UnionAll<T>(List<ISugarQueryable<T>> queryables) where T : class, new();
IUpdateable<T> Updateable<T>() where T : class, new();
IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new();
IUpdateable<T> Updateable<T>(List<T> UpdateObjs) where T : class, new();
IUpdateable<T> Updateable<T>(T UpdateObj) where T : class, new();
IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new();
IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new();
}
}

View File

@@ -71,7 +71,7 @@ namespace SqlSugar
{
var isFirst = whereString == null;
whereString += (isFirst ? null : " AND ");
whereString += Regex.Replace(item, " \\" + this.Builder.SqlTranslationLeft, "T." + this.Builder.SqlTranslationLeft);
whereString += Regex.Replace(item, " \\" + this.Builder.SqlTranslationLeft, "S." + this.Builder.SqlTranslationLeft);
}
}
if (PrimaryKeys.HasValue())

View File

@@ -26,8 +26,11 @@ namespace SqlSugar
PreToSql();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
return result;
}
@@ -37,8 +40,11 @@ namespace SqlSugar
PreToSql();
string sql = InsertBuilder.ToSqlString();
RestoreMapping();
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 :Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
return result;
}

View File

@@ -66,8 +66,8 @@ namespace SqlSugar
}
if (parameters.HasValue())
{
IDataParameter[] ipars = ToIDbDataParameter(parameters);
sqlCommand.Parameters.AddRange((SqlParameter[])ipars);
SqlParameter[] ipars = GetSqlParameter(parameters);
sqlCommand.Parameters.AddRange(ipars);
}
CheckConnection();
return sqlCommand;
@@ -108,5 +108,42 @@ namespace SqlSugar
}
return result;
}
/// <summary>
/// if mysql return MySqlParameter[] pars
/// if sqlerver return SqlParameter[] pars ...
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public SqlParameter[] GetSqlParameter(params SugarParameter[] parameters)
{
if (parameters == null || parameters.Length == 0) return null;
SqlParameter[] result = new SqlParameter[parameters.Length];
int index = 0;
foreach (var parameter in parameters)
{
if (parameter.Value == null) parameter.Value = DBNull.Value;
var sqlParameter = new SqlParameter();
sqlParameter.ParameterName = parameter.ParameterName;
//sqlParameter.UdtTypeName = parameter.UdtTypeName;
sqlParameter.Size = parameter.Size;
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = parameter.DbType;
sqlParameter.Direction = parameter.Direction;
result[index] = sqlParameter;
if (parameter.TypeName.HasValue()) {
sqlParameter.TypeName = parameter.TypeName;
sqlParameter.SqlDbType = SqlDbType.Structured;
sqlParameter.DbType = System.Data.DbType.Object;
}
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue))
{
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
this.OutputParameters.Add(sqlParameter);
}
++index;
}
return result;
}
}
}

View File

@@ -15,7 +15,7 @@ namespace SqlSugar
/// ** date2017/1/2
/// ** email:610262374@qq.com
/// </summary>
public partial class SqlSugarClient : IDisposable
public partial class SqlSugarClient : IDisposable, ISqlSugarClient
{
#region Constructor
@@ -141,6 +141,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2>();
var types = new Type[] { typeof(T2) };
var queryable = InstanceFactory.GetQueryable<T, T2>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3>();
@@ -149,6 +157,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3,JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3>();
var types = new Type[] { typeof(T2), typeof(T3) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4>();
@@ -157,6 +173,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4,JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5>();
@@ -165,6 +189,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5,JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6>();
@@ -173,6 +205,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7>();
@@ -181,6 +221,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8>();
@@ -189,6 +237,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
#region 9-12
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression)
{
@@ -198,6 +254,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>();
@@ -206,6 +270,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>();
@@ -214,6 +286,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
@@ -222,6 +302,14 @@ namespace SqlSugar
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, JoinQueryInfos>> joinExpression)
{
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12) };
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
#endregion
public virtual ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, bool>> joinExpression) where T : class, new()
{