mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Update .net core project
This commit is contained in:
@@ -253,7 +253,32 @@ namespace SqlSugar
|
||||
this.Context.Ado.ExecuteCommand(string.Format(this.DropTableSql, tableName));
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool DropTable<T>()
|
||||
{
|
||||
var tableName= this.Context.EntityMaintenance.GetTableName<T>();
|
||||
return DropTable(tableName);
|
||||
}
|
||||
public virtual bool DropTable<T,T2>()
|
||||
{
|
||||
DropTable<T>();
|
||||
DropTable<T2>();
|
||||
return true;
|
||||
}
|
||||
public virtual bool DropTable<T, T2,T3>()
|
||||
{
|
||||
DropTable<T>();
|
||||
DropTable<T2>();
|
||||
DropTable<T3>();
|
||||
return true;
|
||||
}
|
||||
public virtual bool DropTable<T, T2, T3,T4>()
|
||||
{
|
||||
DropTable<T>();
|
||||
DropTable<T2>();
|
||||
DropTable<T3>();
|
||||
DropTable<T4>();
|
||||
return true;
|
||||
}
|
||||
public virtual bool TruncateTable<T>()
|
||||
{
|
||||
this.Context.InitMappingInfo<T>();
|
||||
|
@@ -48,12 +48,13 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Select DTO error . Warning:"+ex.Message);
|
||||
result = Action(expression, queryableProvider);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
throw ex;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,36 +104,7 @@ namespace SqlSugar
|
||||
|
||||
internal static async Task<List<TResult>> GetListAsync<T, TResult>(Expression<Func<T, TResult>> expression, QueryableProvider<T> queryableProvider)
|
||||
{
|
||||
List<TResult> result = new List<TResult>();
|
||||
var isSqlFunc = IsSqlFunc(expression, queryableProvider);
|
||||
if (isSqlFunc && isGroup(expression, queryableProvider))
|
||||
{
|
||||
var sqlfuncQueryable = queryableProvider.Clone();
|
||||
sqlfuncQueryable.QueryBuilder.Includes = null;
|
||||
result =await sqlfuncQueryable
|
||||
.Select(expression)
|
||||
.ToListAsync();
|
||||
var includeQueryable = queryableProvider.Clone();
|
||||
includeQueryable.Select(GetGroupSelect(typeof(T), queryableProvider.Context, queryableProvider.QueryBuilder));
|
||||
includeQueryable.QueryBuilder.NoCheckInclude = true;
|
||||
MegerList(result,await includeQueryable.ToListAsync(), sqlfuncQueryable.Context);
|
||||
}
|
||||
else if (isSqlFunc)
|
||||
{
|
||||
var sqlfuncQueryable = queryableProvider.Clone();
|
||||
sqlfuncQueryable.QueryBuilder.Includes = null;
|
||||
result =await sqlfuncQueryable
|
||||
.Select(expression)
|
||||
.ToListAsync();
|
||||
var includeList =await queryableProvider.Clone().ToListAsync();
|
||||
MegerList(result, includeList, sqlfuncQueryable.Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list =await queryableProvider.ToListAsync();
|
||||
result = list.Select(expression.Compile()).ToList();
|
||||
}
|
||||
return result;
|
||||
return await Task.Run(()=> { return GetList(expression,queryableProvider); });
|
||||
}
|
||||
|
||||
private static string GetGroupSelect(Type type,SqlSugarProvider context,QueryBuilder queryBuilder)
|
||||
|
@@ -605,5 +605,30 @@ namespace SqlSugar
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual string JsonField(MethodCallExpressionModel model)
|
||||
{
|
||||
throw new NotImplementedException("Current database no support");
|
||||
}
|
||||
|
||||
public virtual string JsonContainsFieldName(MethodCallExpressionModel model)
|
||||
{
|
||||
throw new NotImplementedException("Current database no support");
|
||||
}
|
||||
|
||||
public virtual string JsonArrayLength(MethodCallExpressionModel model)
|
||||
{
|
||||
throw new NotImplementedException("Current database no support");
|
||||
}
|
||||
|
||||
public virtual string JsonParse(MethodCallExpressionModel model)
|
||||
{
|
||||
throw new NotImplementedException("Current database no support");
|
||||
}
|
||||
public string JsonLike(MethodCallExpressionModel model)
|
||||
{
|
||||
model.Args[0].MemberName = ToString(model);
|
||||
return Contains(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -92,5 +92,10 @@ namespace SqlSugar
|
||||
string Exists(MethodCallExpressionModel model);
|
||||
string GetDateString(string dateValue,string format);
|
||||
string GetForXmlPath();
|
||||
string JsonField(MethodCallExpressionModel model);
|
||||
string JsonContainsFieldName(MethodCallExpressionModel model);
|
||||
string JsonArrayLength(MethodCallExpressionModel model);
|
||||
string JsonParse(MethodCallExpressionModel model);
|
||||
string JsonLike(MethodCallExpressionModel model);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,49 @@ namespace SqlSugar
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static string JsonField(object json,string fieldName)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static string JsonField(object json, string fieldName,string includeFieldName)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName, string ThenIncludeFieldName2)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName, string ThenIncludeFieldName2, string ThenIncludeFieldName3)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool JsonContainsFieldName(object json, string fieldName)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static int JsonArrayLength(object json)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static string JsonParse(object json)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static bool JsonLike(object json,string likeStr)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static T Desc<T>(T value)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
|
@@ -1028,6 +1028,17 @@ namespace SqlSugar
|
||||
this.Context.Parameters.AddRange(sqlObj.Value);
|
||||
}
|
||||
return this.Context.DbMehtods.Exists(model);
|
||||
|
||||
case "JsonField":
|
||||
return this.Context.DbMehtods.JsonField(model);
|
||||
case "JsonArrayLength":
|
||||
return this.Context.DbMehtods.JsonArrayLength(model);
|
||||
case "JsonContainsFieldName":
|
||||
return this.Context.DbMehtods.JsonContainsFieldName(model);
|
||||
case "JsonParse":
|
||||
return this.Context.DbMehtods.JsonParse(model);
|
||||
case "JsonLike":
|
||||
return this.Context.DbMehtods.JsonLike(model);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -32,6 +32,10 @@ namespace SqlSugar
|
||||
bool CreateIndex(string tableName, string [] columnNames, bool isUnique=false);
|
||||
bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false);
|
||||
bool DropTable(string tableName);
|
||||
bool DropTable<T>();
|
||||
bool DropTable<T,T2>();
|
||||
bool DropTable<T, T2,T3>();
|
||||
bool DropTable<T, T2, T3,T4>();
|
||||
bool TruncateTable(string tableName);
|
||||
bool TruncateTable<T>();
|
||||
bool TruncateTable<T,T2>();
|
||||
|
@@ -384,5 +384,64 @@ namespace SqlSugar
|
||||
{
|
||||
return "( " + fieldName + "=true )";
|
||||
}
|
||||
|
||||
public override string JsonField(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter1 = model.Args[1];
|
||||
//var parameter2 = model.Args[2];
|
||||
//var parameter3= model.Args[3];
|
||||
var result= GetJson(parameter.MemberName, parameter1.MemberName, model.Args.Count()==2);
|
||||
if (model.Args.Count > 2)
|
||||
{
|
||||
result = GetJson(result, model.Args[2].MemberName, model.Args.Count() == 3);
|
||||
}
|
||||
if (model.Args.Count > 3)
|
||||
{
|
||||
result = GetJson(result, model.Args[3].MemberName, model.Args.Count() == 4);
|
||||
}
|
||||
if (model.Args.Count > 4)
|
||||
{
|
||||
result = GetJson(result, model.Args[4].MemberName, model.Args.Count() == 5);
|
||||
}
|
||||
if (model.Args.Count > 5)
|
||||
{
|
||||
result = GetJson(result, model.Args[5].MemberName, model.Args.Count() == 6);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string JsonContainsFieldName(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter1 = model.Args[1];
|
||||
return $"({parameter.MemberName}::jsonb ?{parameter1.MemberName})";
|
||||
}
|
||||
|
||||
private string GetJson(object memberName1, object memberName2,bool isLast)
|
||||
{
|
||||
if (isLast)
|
||||
{
|
||||
return $"({memberName1}::json->>{memberName2})";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"({memberName1}->{memberName2})";
|
||||
}
|
||||
}
|
||||
|
||||
public override string JsonArrayLength(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
//var parameter1 = model.Args[1];
|
||||
return $" json_array_length({parameter.MemberName}::json) ";
|
||||
}
|
||||
|
||||
public override string JsonParse(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
//var parameter1 = model.Args[1];
|
||||
return $" ({parameter.MemberName}::json) ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user