Browse Source

Synchronization code

pull/40/head
sunkaixuan 1 year ago
parent
commit
da44efc748
  1. 11
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs
  2. 13
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs
  3. 30
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  4. 3
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  5. 17
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  6. 2
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs
  7. 4
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs
  8. 13
      Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmExpressionContext.cs
  9. 12
      Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  10. 8
      Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs
  11. 22
      Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

11
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

@ -353,7 +353,11 @@ namespace SqlSugar
var list = this.ToList();
return TreeAndFilterIds(childListExpression, parentIdExpression, rootValue, childIds, ref list) ?? new List<T>();
}
public virtual DataTable ToDataTableByEntity()
{
var list = this.ToList();
return this.Context.Utilities.ListToDataTable(list);
}
public virtual DataTable ToDataTable()
{
QueryBuilder.ResultType = typeof(SugarCacheDataTable);
@ -392,6 +396,11 @@ namespace SqlSugar
}
return ToDataTable();
}
public DataTable ToDataTableByEntityPage(int pageNumber, int pageSize, ref int totalNumber)
{
var list=this.ToPageList(pageNumber, pageSize,ref totalNumber);
return this.Context.Utilities.ListToDataTable(list);
}
public virtual DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber)
{
_RestoreMapping = false;

13
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSqlAsync.cs

@ -10,7 +10,7 @@ using System.Reflection;
using System.Dynamic;
using System.Threading.Tasks;
using System.Threading;
namespace SqlSugar
{
@ -350,7 +350,11 @@ namespace SqlSugar
this.Context.MappingTables = oldMapping;
return await this.Clone().ToJsonPageAsync(pageIndex, pageSize);
}
public async virtual Task<DataTable> ToDataTableByEntityAsync()
{
var list =await this.ToListAsync();
return this.Context.Utilities.ListToDataTable(list);
}
public async Task<DataTable> ToDataTableAsync()
{
QueryBuilder.ResultType = typeof(SugarCacheDataTable);
@ -381,6 +385,11 @@ namespace SqlSugar
this.Context.MappingTables = oldMapping;
return await this.Clone().ToDataTablePageAsync(pageIndex, pageSize);
}
public async Task<DataTable> ToDataTableByEntityPageAsync(int pageNumber, int pageSize, RefAsync<int> totalNumber)
{
var list =await this.ToPageListAsync(pageNumber, pageSize, totalNumber);
return this.Context.Utilities.ListToDataTable(list);
}
public async Task<List<T>> ToOffsetPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
{
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)

30
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -770,6 +770,12 @@ namespace SqlSugar
var value1 = MergeString(value, "','");
var value2 = MergeString("','", value);
var value3 = MergeString("','", value, "','");
if (model.Args.Count == 3)
{
value1 = value1.Replace("','", model.Args[2].MemberName+"" );
value2 = value2.Replace("','", model.Args[2].MemberName + "" );
value3 = value3.Replace("','", model.Args[2].MemberName + "" );
}
var likeString1 =
StartsWith(new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ IsMember=true, MemberName=fullString },
@ -1016,14 +1022,34 @@ namespace SqlSugar
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB= mode.Args[1].MemberName;
return @$" CASE WHEN RIGHT({parameterNameA}, 1) = {parameterNameB} THEN LEFT({parameterNameA}, LENGTH({parameterNameA}) - 1) ELSE {parameterNameA} END ";
return $" CASE WHEN RIGHT({parameterNameA}, 1) = {parameterNameB} THEN LEFT({parameterNameA}, LENGTH({parameterNameA}) - 1) ELSE {parameterNameA} END ";
}
public virtual string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return @$" CASE WHEN LEFT({parameterNameA}, 1) = {parameterNameB} THEN RIGHT({parameterNameA}, LEN({parameterNameA}) - 1) ELSE {parameterNameA} END ";
return $" CASE WHEN LEFT({parameterNameA}, 1) = {parameterNameB} THEN RIGHT({parameterNameA}, LEN({parameterNameA}) - 1) ELSE {parameterNameA} END ";
}
public virtual string Left(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LEFT({parameterNameA},{parameterNameB}) ";
}
public virtual string Right(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" RIGHT({parameterNameA},{parameterNameB}) ";
}
public virtual string PadLeft(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
var parameterNameC = mode.Args[2].MemberName;
return $" LPAD({parameterNameA},{parameterNameB},{parameterNameC}) ";
}
}
}

3
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -116,5 +116,8 @@ namespace SqlSugar
string WeekOfYear(MethodCallExpressionModel mode);
string TrimEnd(MethodCallExpressionModel mode);
string TrimStart(MethodCallExpressionModel mode);
string Left(MethodCallExpressionModel mode);
string Right(MethodCallExpressionModel mode);
string PadLeft(MethodCallExpressionModel mode);
}
}

17
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -13,6 +13,18 @@ namespace SqlSugar
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string Left(string value,int number)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string Right(string value,int number)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string PadLeft(string value,int number, char padChar)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool Like(string fieldName, string likeValue)
{
throw new NotSupportedException("Can only be used in expressions");
@ -344,6 +356,11 @@ namespace SqlSugar
throw new NotSupportedException("Can only be used in expressions");
}
public static bool SplitIn(string CommaSegmentationString, string inValue,char splitChar)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool ListAny<T>(List<T> listConstant, Expression<Func<T,bool>> expression)
{
throw new NotSupportedException("Can only be used in expressions");

2
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -53,7 +53,7 @@ namespace SqlSugar
var type = expression.Type;
var memberName = this.Context.GetDbColumnName(type.Name, memberAssignment.Member.Name);
var item = memberAssignment.Expression;
item = ExpressionTool.RemoveConvert(item);
//Column IsJson Handler
if (memberAssignment.Member.CustomAttributes != null)
{

4
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -234,12 +234,16 @@ namespace SqlSugar
List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds);
Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds);
DataTable ToDataTable();
DataTable ToDataTableByEntity();
Task<DataTable> ToDataTableAsync();
Task<DataTable> ToDataTableByEntityAsync();
DataTable ToDataTablePage(int pageNumber, int pageSize);
Task<DataTable> ToDataTablePageAsync(int pageNumber, int pageSize);
DataTable ToDataTablePage(int pageNumber, int pageSize, ref int totalNumber);
DataTable ToDataTableByEntityPage(int pageNumber, int pageSize, ref int totalNumber);
DataTable ToDataTablePage(int pageNumber, int pageSize, ref int totalNumber,ref int totalPage);
Task<DataTable> ToDataTablePageAsync(int pageNumber, int pageSize, RefAsync<int> totalNumber);
Task<DataTable> ToDataTableByEntityPageAsync(int pageNumber, int pageSize, RefAsync<int> totalNumber);
List<T> ToOffsetPage(int pageNumber, int pageSize);
List<T> ToOffsetPage(int pageNumber, int pageSize,ref int totalNumber);

13
Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmExpressionContext.cs

@ -240,5 +240,18 @@ namespace SqlSugar
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM({parameterNameA}, {parameterNameB}) ";
}
public override string Left(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, 1, {parameterNameB}) ";
}
public override string Right(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, -2, {parameterNameB}) ";
}
}
}

12
Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -366,5 +366,17 @@ namespace SqlSugar
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM({parameterNameA}, {parameterNameB}) ";
}
public override string Left(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, 1, {parameterNameB}) ";
}
public override string Right(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, -2, {parameterNameB}) ";
}
}
}

8
Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs

@ -122,6 +122,14 @@ namespace SqlSugar
var parameterNameB = mode.Args[1].MemberName;
return $" CASE WHEN LEFT({parameterNameA}, 1) = {parameterNameB} THEN RIGHT({parameterNameA}, LEN({parameterNameA}) - 1) ELSE {parameterNameA} END ";
}
public override string PadLeft(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
var parameterNameC = mode.Args[2].MemberName;
return $" CONCAT(REPLICATE({parameterNameC}, {parameterNameB} - LEN({parameterNameA})), {parameterNameA}) ";
}
}

22
Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -297,5 +297,27 @@ namespace SqlSugar
var parameterNameB = mode.Args[1].MemberName;
return $" CASE WHEN SUBSTR({parameterNameA}, 1, 1) ={parameterNameB} THEN SUBSTR({parameterNameA}, 2) ELSE {parameterNameA} END ";
}
public override string PadLeft(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
var parameterNameC = mode.Args[2].MemberName;
var value = new string[mode.Args[1].MemberValue.ObjToInt()].Select(it=> parameterNameC);
return $"substr({string.Join("||", value)} || {parameterNameA}, {parameterNameB}*-1) ";
}
public override string Left(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, 1, {parameterNameB}) ";
}
public override string Right(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" SUBSTR({parameterNameA}, -2, {parameterNameB}) ";
}
}
}

Loading…
Cancel
Save