mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-09 02:44:58 +08:00
Synchronous code
This commit is contained in:
@@ -207,6 +207,7 @@ namespace SqlSugar
|
|||||||
#region Core Logic
|
#region Core Logic
|
||||||
private void GetDifferenceTables(TableDifferenceProvider result, Type type)
|
private void GetDifferenceTables(TableDifferenceProvider result, Type type)
|
||||||
{
|
{
|
||||||
|
var isCreate = false;
|
||||||
var tempTableName = "TempDiff" + DateTime.Now.ToString("yyMMssHHmmssfff");
|
var tempTableName = "TempDiff" + DateTime.Now.ToString("yyMMssHHmmssfff");
|
||||||
var oldTableName = this.Context.EntityMaintenance.GetEntityInfo(type).DbTableName;
|
var oldTableName = this.Context.EntityMaintenance.GetEntityInfo(type).DbTableName;
|
||||||
var db = new SqlSugarProvider(UtilMethods.CopyConfig(this.Context.CurrentConnectionConfig));
|
var db = new SqlSugarProvider(UtilMethods.CopyConfig(this.Context.CurrentConnectionConfig));
|
||||||
@@ -224,6 +225,7 @@ namespace SqlSugar
|
|||||||
var codeFirst=db.CodeFirst;
|
var codeFirst=db.CodeFirst;
|
||||||
codeFirst.SetStringDefaultLength(this.DefultLength);
|
codeFirst.SetStringDefaultLength(this.DefultLength);
|
||||||
codeFirst.InitTables(type);
|
codeFirst.InitTables(type);
|
||||||
|
isCreate = true;
|
||||||
var tables = db.DbMaintenance.GetTableInfoList(false);
|
var tables = db.DbMaintenance.GetTableInfoList(false);
|
||||||
var oldTableInfo = tables.FirstOrDefault(it=>it.Name.EqualCase(oldTableName));
|
var oldTableInfo = tables.FirstOrDefault(it=>it.Name.EqualCase(oldTableName));
|
||||||
var newTableInfo = tables.FirstOrDefault(it => it.Name.EqualCase(oldTableName));
|
var newTableInfo = tables.FirstOrDefault(it => it.Name.EqualCase(oldTableName));
|
||||||
@@ -247,10 +249,13 @@ namespace SqlSugar
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
{
|
||||||
|
if (isCreate)
|
||||||
{
|
{
|
||||||
db.DbMaintenance.DropTable(tempTableName);
|
db.DbMaintenance.DropTable(tempTableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected virtual void Execute(Type entityType,EntityInfo entityInfo)
|
protected virtual void Execute(Type entityType,EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
||||||
|
|||||||
@@ -106,28 +106,29 @@ namespace SqlSugar
|
|||||||
Type mappingTableType = navigate.MappingType;
|
Type mappingTableType = navigate.MappingType;
|
||||||
string typeAiD = navigate.MappingAId;
|
string typeAiD = navigate.MappingAId;
|
||||||
string typeBId = navigate.MappingBId;
|
string typeBId = navigate.MappingBId;
|
||||||
|
var queryPropertyNames = navigate.QueryPropertyNames;
|
||||||
ConstructorInfo constructor;
|
ConstructorInfo constructor;
|
||||||
object[] constructorArgs;
|
object[] constructorArgs;
|
||||||
|
|
||||||
if (mappingTableType != null && typeAiD != null && typeBId != null)
|
if (mappingTableType != null && typeAiD != null && typeBId != null)
|
||||||
{
|
{
|
||||||
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(Type), typeof(string), typeof(string), typeof(string) });
|
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(Type), typeof(string), typeof(string), typeof(string), typeof(string[]) });
|
||||||
constructorArgs = new object[] { mappingTableType, typeAiD, typeBId, whereSql };
|
constructorArgs = new object[] { mappingTableType, typeAiD, typeBId, whereSql , queryPropertyNames };
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(whereSql))
|
else if (!string.IsNullOrEmpty(whereSql))
|
||||||
{
|
{
|
||||||
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string) });
|
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string), typeof(string[]) });
|
||||||
constructorArgs = new object[] { navigatType, name, name2, whereSql };
|
constructorArgs = new object[] { navigatType, name, name2, whereSql, queryPropertyNames };
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(name2))
|
else if (!string.IsNullOrEmpty(name2))
|
||||||
{
|
{
|
||||||
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string) });
|
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string), typeof(string[]) });
|
||||||
constructorArgs = new object[] { navigatType, name, name2 };
|
constructorArgs = new object[] { navigatType, name, name2, queryPropertyNames };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string) });
|
constructor = typeof(Navigate).GetConstructor(new Type[] { typeof(NavigateType), typeof(string), typeof(string[]) });
|
||||||
constructorArgs = new object[] { navigatType, name };
|
constructorArgs = new object[] { navigatType, name, queryPropertyNames };
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CustomAttributeBuilder(constructor, constructorArgs);
|
return new CustomAttributeBuilder(constructor, constructorArgs);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Linq.Expressions;
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public partial class FastestProvider<T>:IFastest<T> where T:class,new()
|
public partial class FastestProvider<T>:IFastest<T> where T:class,new()
|
||||||
@@ -244,6 +245,21 @@ namespace SqlSugar
|
|||||||
return BulkMergeAsync(datas, whereColumns, updateColumns).GetAwaiter().GetResult();
|
return BulkMergeAsync(datas, whereColumns, updateColumns).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> BulkMergeAsync(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp)
|
||||||
|
{
|
||||||
|
// 1. 获取 whereColumns
|
||||||
|
var whereColumns =ExpressionTool.GetNewExpressionItemListNew((whereColumnsExp as LambdaExpression).Body).Select(it=>it.Key).ToArray();
|
||||||
|
// 2. 获取 updateColumns
|
||||||
|
var updateColumns = ExpressionTool.GetNewExpressionItemListNew((updateColumnsExp as LambdaExpression).Body).Select(it => it.Key).ToArray();
|
||||||
|
|
||||||
|
// 3. 调用 BulkMergeAsync
|
||||||
|
return await BulkMergeAsync(datas, whereColumns, updateColumns);
|
||||||
|
}
|
||||||
|
public int BulkMerge(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp)
|
||||||
|
{
|
||||||
|
return BulkMergeAsync(datas, whereColumnsExp, updateColumnsExp).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<int> _BulkMerge(List<T> datas, string[] updateColumns, string[] whereColumns)
|
private async Task<int> _BulkMerge(List<T> datas, string[] updateColumns, string[] whereColumns)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Data;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
@@ -98,13 +99,43 @@ namespace SqlSugar
|
|||||||
dt.Columns.Add(item.ColumnName, item.DataType);
|
dt.Columns.Add(item.ColumnName, item.DataType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool supportIdentity = true;
|
||||||
|
if (this.context.CurrentConnectionConfig.DbType == DbType.PostgreSQL || this.context.CurrentConnectionConfig.DbType == DbType.Vastbase)
|
||||||
|
{
|
||||||
|
supportIdentity = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!supportIdentity)
|
||||||
|
{
|
||||||
|
// PostgreSQL/Vastbase不支持自增主键导入
|
||||||
|
foreach (var identityColumnInfo in this.entityInfo.Columns.Where(it => it.IsIdentity))
|
||||||
|
{
|
||||||
|
if (dt.Columns.Contains(identityColumnInfo.DbColumnName))
|
||||||
|
{
|
||||||
|
dt.Columns.Remove(identityColumnInfo.DbColumnName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dt.TableName = GetTableName();
|
dt.TableName = GetTableName();
|
||||||
var columns = entityInfo.Columns;
|
var columns = supportIdentity ? entityInfo.Columns : entityInfo.Columns.Where(it => !it.IsIdentity).ToList();
|
||||||
if (columns.Where(it=>!it.IsIgnore).Count() > tempDataTable.Columns.Count)
|
if (columns.Where(it=>!it.IsIgnore).Count() > tempDataTable.Columns.Count)
|
||||||
{
|
{
|
||||||
var tempColumns = tempDataTable.Columns.Cast<DataColumn>().Select(it=>it.ColumnName);
|
var tempColumns = tempDataTable.Columns.Cast<DataColumn>().Select(it=>it.ColumnName);
|
||||||
columns = columns.Where(it => tempColumns.Any(s => s.EqualCase(it.DbColumnName))).ToList();
|
columns = columns.Where(it => tempColumns.Any(s => s.EqualCase(it.DbColumnName))).ToList();
|
||||||
}
|
}
|
||||||
|
MyTuple myTuple = GetDiscrimator();
|
||||||
|
|
||||||
|
if (myTuple.isDiscrimator && myTuple.discrimatorDict?.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var dict in myTuple.discrimatorDict)
|
||||||
|
{
|
||||||
|
if (!dt.Columns.Contains(dict.Key))
|
||||||
|
dt.Columns.Add(dict.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var isMySql = this.context.CurrentConnectionConfig.DbType.IsIn(DbType.MySql, DbType.MySqlConnector);
|
var isMySql = this.context.CurrentConnectionConfig.DbType.IsIn(DbType.MySql, DbType.MySqlConnector);
|
||||||
var isSqliteCore = SugarCompatible.IsFramework==false&& this.context.CurrentConnectionConfig.DbType.IsIn(DbType.Sqlite);
|
var isSqliteCore = SugarCompatible.IsFramework==false&& this.context.CurrentConnectionConfig.DbType.IsIn(DbType.Sqlite);
|
||||||
foreach (var item in datas)
|
foreach (var item in datas)
|
||||||
@@ -168,6 +199,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
dr[name] = value;
|
dr[name] = value;
|
||||||
}
|
}
|
||||||
|
if (myTuple.isDiscrimator && myTuple.discrimatorDict?.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var dict in myTuple.discrimatorDict)
|
||||||
|
{
|
||||||
|
var key = dict.Key; var val = dict.Value;
|
||||||
|
if (!string.IsNullOrWhiteSpace(val) && string.IsNullOrWhiteSpace(dr[key] + ""))
|
||||||
|
dr[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
dt.Rows.Add(dr);
|
dt.Rows.Add(dr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,5 +393,36 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MyTuple GetDiscrimator()
|
||||||
|
{
|
||||||
|
var isDiscrimator = entityInfo.Discrimator.HasValue();
|
||||||
|
var dict = new Dictionary<string, string>();
|
||||||
|
if (isDiscrimator)
|
||||||
|
{
|
||||||
|
Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格");
|
||||||
|
var array = entityInfo.Discrimator.Split(',');
|
||||||
|
foreach (var disItem in array)
|
||||||
|
{
|
||||||
|
var name = disItem.Split(':').First();
|
||||||
|
var value = disItem.Split(':').Last();
|
||||||
|
if(!dict.ContainsKey(name))
|
||||||
|
dict.Add(name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new MyTuple(isDiscrimator, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class MyTuple
|
||||||
|
{
|
||||||
|
public bool isDiscrimator;
|
||||||
|
public Dictionary<string, string> discrimatorDict;
|
||||||
|
|
||||||
|
public MyTuple(bool isDiscrimator, Dictionary<string, string> dict)
|
||||||
|
{
|
||||||
|
this.isDiscrimator = isDiscrimator;
|
||||||
|
this.discrimatorDict = dict;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var name = disItem.Split(':').First();
|
var name = disItem.Split(':').First();
|
||||||
var value = disItem.Split(':').Last();
|
var value = disItem.Split(':').Last();
|
||||||
insertItem.Add(new DbColumnInfo() { DbColumnName = name, PropertyName = name, PropertyType = typeof(string), Value = value });
|
insertItem.Add(new DbColumnInfo() { TableId=i, DbColumnName = name, PropertyName = name, PropertyType = typeof(string), Value = value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,7 +271,11 @@ namespace SqlSugar
|
|||||||
var sql = GetWhereSql(GetCrossDatabase(abDb, bEntity));
|
var sql = GetWhereSql(GetCrossDatabase(abDb, bEntity));
|
||||||
if (sql.SelectString == null)
|
if (sql.SelectString == null)
|
||||||
{
|
{
|
||||||
|
//加载指定列
|
||||||
|
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
|
||||||
|
|
||||||
var columns = bEntityInfo.Columns.Where(it => !it.IsIgnore)
|
var columns = bEntityInfo.Columns.Where(it => !it.IsIgnore)
|
||||||
|
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
|
||||||
.Select(it => GetOneToManySelectByColumnInfo(it, abDb)).ToList();
|
.Select(it => GetOneToManySelectByColumnInfo(it, abDb)).ToList();
|
||||||
sql.SelectString = String.Join(",", columns);
|
sql.SelectString = String.Join(",", columns);
|
||||||
}
|
}
|
||||||
@@ -433,7 +437,11 @@ namespace SqlSugar
|
|||||||
var sqlObj = GetWhereSql(db, navObjectNameColumnInfo.Navigat.Name);
|
var sqlObj = GetWhereSql(db, navObjectNameColumnInfo.Navigat.Name);
|
||||||
if (sqlObj.SelectString == null)
|
if (sqlObj.SelectString == null)
|
||||||
{
|
{
|
||||||
|
// 加载指定列
|
||||||
|
var queryPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
|
||||||
|
|
||||||
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
||||||
|
.WhereIF(queryPropertyNames != null && queryPropertyNames.Length > 0, it => queryPropertyNames.Contains(it.PropertyName))
|
||||||
.Select(it => GetOneToOneSelectByColumnInfo(it, db)).ToList();
|
.Select(it => GetOneToOneSelectByColumnInfo(it, db)).ToList();
|
||||||
sqlObj.SelectString = String.Join(",", columns);
|
sqlObj.SelectString = String.Join(",", columns);
|
||||||
}
|
}
|
||||||
@@ -581,7 +589,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (sqlObj.SelectString == null)
|
if (sqlObj.SelectString == null)
|
||||||
{
|
{
|
||||||
|
//加载指定列
|
||||||
|
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
|
||||||
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
||||||
|
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
|
||||||
.Select(it => GetOneToManySelectByColumnInfo(it, childDb)).ToList();
|
.Select(it => GetOneToManySelectByColumnInfo(it, childDb)).ToList();
|
||||||
sqlObj.SelectString = String.Join(",", columns);
|
sqlObj.SelectString = String.Join(",", columns);
|
||||||
}
|
}
|
||||||
@@ -699,7 +710,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (sqlObj.SelectString == null)
|
if (sqlObj.SelectString == null)
|
||||||
{
|
{
|
||||||
|
//加载指定列
|
||||||
|
var manualPropertyNames = GetQueryPropertyNames(navObjectNameColumnInfo);
|
||||||
|
|
||||||
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
var columns = navEntityInfo.Columns.Where(it => !it.IsIgnore)
|
||||||
|
.WhereIF(manualPropertyNames != null && manualPropertyNames.Length > 0, it => manualPropertyNames.Contains(it.PropertyName))
|
||||||
.Select(it => GetOneToManySelectByColumnInfo(it,childDb)).ToList();
|
.Select(it => GetOneToManySelectByColumnInfo(it,childDb)).ToList();
|
||||||
sqlObj.SelectString = String.Join(",", columns);
|
sqlObj.SelectString = String.Join(",", columns);
|
||||||
}
|
}
|
||||||
@@ -1252,5 +1267,38 @@ namespace SqlSugar
|
|||||||
return QueryBuilder.Builder.GetTranslationColumnName(it.DbColumnName) + " AS " + QueryBuilder.Builder.GetTranslationColumnName(it.PropertyName);
|
return QueryBuilder.Builder.GetTranslationColumnName(it.DbColumnName) + " AS " + QueryBuilder.Builder.GetTranslationColumnName(it.PropertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取查询的属性名称列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="navObjectNamePropety"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private string[] GetQueryPropertyNames(EntityColumnInfo navObjectNameColumnInfo)
|
||||||
|
{
|
||||||
|
string[] queryPropertyNames = null;
|
||||||
|
if (navObjectNameColumnInfo?.Navigat?.QueryPropertyNames?.Any()==true)
|
||||||
|
{
|
||||||
|
var navInfo = navObjectNameColumnInfo?.Navigat;
|
||||||
|
queryPropertyNames = navObjectNameColumnInfo.Navigat.QueryPropertyNames;
|
||||||
|
var list = queryPropertyNames.ToList();
|
||||||
|
if (navInfo.AClassId != null)
|
||||||
|
{
|
||||||
|
list.Add(navInfo.AClassId);
|
||||||
|
}
|
||||||
|
if (navInfo.BClassId != null)
|
||||||
|
{
|
||||||
|
list.Add(navInfo.BClassId);
|
||||||
|
}
|
||||||
|
if (navInfo.Name != null)
|
||||||
|
{
|
||||||
|
list.Add(navInfo.Name);
|
||||||
|
}
|
||||||
|
if (navInfo.Name2 != null)
|
||||||
|
{
|
||||||
|
list.Add(navInfo.Name2);
|
||||||
|
}
|
||||||
|
queryPropertyNames = list.ToArray();
|
||||||
|
}
|
||||||
|
return queryPropertyNames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var copyDb = this.Clone();
|
var copyDb = this.Clone();
|
||||||
copyDb.QueryBuilder.OrderByValue = null;
|
copyDb.QueryBuilder.OrderByValue = null;
|
||||||
|
copyDb.QueryBuilder.Includes = null;
|
||||||
var list = await copyDb.Select<int>(" COUNT(1) ").ToListAsync();
|
var list = await copyDb.Select<int>(" COUNT(1) ").ToListAsync();
|
||||||
return list.FirstOrDefault();
|
return list.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -866,6 +866,15 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
propertyInfo.SetValue(addItem,UtilMethods.To( kv.Value, propertyInfo.PropertyType));
|
propertyInfo.SetValue(addItem,UtilMethods.To( kv.Value, propertyInfo.PropertyType));
|
||||||
}
|
}
|
||||||
|
else if (kv.Value is string s&&
|
||||||
|
s!=null&&
|
||||||
|
s?.StartsWith("[")==true&&
|
||||||
|
s?.EndsWith("]") == true&&
|
||||||
|
UtilMethods.IsArrayOrList(propertyInfo.PropertyType)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
propertyInfo.SetValue(addItem, UtilMethods.ConvertToArray(kv.Value?.ToString(), propertyInfo.PropertyType));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
propertyInfo.SetValue(addItem, kv.Value);
|
propertyInfo.SetValue(addItem, kv.Value);
|
||||||
|
|||||||
@@ -216,8 +216,15 @@ namespace SqlSugar
|
|||||||
if (isLeftJoin == false)
|
if (isLeftJoin == false)
|
||||||
{
|
{
|
||||||
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
|
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
|
||||||
|
if (oldAsName?.Any() == false && result.QueryBuilder.AsTables?.Any() == true)
|
||||||
|
{
|
||||||
|
//no things
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
result.QueryBuilder.AsTables = oldAsName;
|
result.QueryBuilder.AsTables = oldAsName;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T, T2> InnerJoinIF<T2>(bool isJoin, Expression<Func<T, T2, bool>> joinExpression)
|
public ISugarQueryable<T, T2> InnerJoinIF<T2>(bool isJoin, Expression<Func<T, T2, bool>> joinExpression)
|
||||||
@@ -227,8 +234,15 @@ namespace SqlSugar
|
|||||||
if (isJoin == false)
|
if (isJoin == false)
|
||||||
{
|
{
|
||||||
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
|
result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last());
|
||||||
|
if (oldAsName?.Any() == false && result.QueryBuilder.AsTables?.Any() == true)
|
||||||
|
{
|
||||||
|
//no things
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
result.QueryBuilder.AsTables = oldAsName;
|
result.QueryBuilder.AsTables = oldAsName;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T, T2> LeftJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
|
public ISugarQueryable<T, T2> LeftJoin<T2>(Expression<Func<T, T2, bool>> joinExpression)
|
||||||
|
|||||||
@@ -215,6 +215,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return $" CAST( NULL AS timestamp) ";
|
return $" CAST( NULL AS timestamp) ";
|
||||||
}
|
}
|
||||||
|
else if (entityColumnInfo != null && entityColumnInfo.IsJson && value!=null)
|
||||||
|
{
|
||||||
|
return $"'{this.Context.Utilities.SerializeObject(value).ToSqlFilter()}'";
|
||||||
|
}
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return "null";
|
return "null";
|
||||||
var type =UtilMethods.GetUnderType(value.GetType());
|
var type =UtilMethods.GetUnderType(value.GetType());
|
||||||
|
|||||||
@@ -527,6 +527,9 @@ namespace SqlSugar
|
|||||||
break;
|
break;
|
||||||
case DbType.PolarDB:
|
case DbType.PolarDB:
|
||||||
config.DbType = DbType.MySql;
|
config.DbType = DbType.MySql;
|
||||||
|
if (this.CurrentConnectionConfig.MoreSettings == null)
|
||||||
|
this.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings();
|
||||||
|
this.CurrentConnectionConfig.MoreSettings.DatabaseModel = DbType.PolarDB;
|
||||||
break;
|
break;
|
||||||
case DbType.TDSQL:
|
case DbType.TDSQL:
|
||||||
config.DbType = DbType.MySql;
|
config.DbType = DbType.MySql;
|
||||||
|
|||||||
@@ -275,7 +275,18 @@ namespace SqlSugar
|
|||||||
public IUpdateable<T, T2> InnerJoin<T2>(ISugarQueryable<T2> queryable, Expression<Func<T, T2, bool>> joinExpress)
|
public IUpdateable<T, T2> InnerJoin<T2>(ISugarQueryable<T2> queryable, Expression<Func<T, T2, bool>> joinExpress)
|
||||||
{
|
{
|
||||||
var tableName = $" ({queryable.Clone().ToSqlString()}) "; ;
|
var tableName = $" ({queryable.Clone().ToSqlString()}) "; ;
|
||||||
return this.InnerJoin(joinExpress, tableName);
|
return this.InnerJoin<T2>(tableName, joinExpress,this.UpdateBuilder.TableName);
|
||||||
|
}
|
||||||
|
public IUpdateable<T, T2> InnerJoin<T2>(string joinTable, Expression<Func<T, T2, bool>> joinExpress, string tableName)
|
||||||
|
{
|
||||||
|
UpdateableProvider<T, T2> result = new UpdateableProvider<T, T2>();
|
||||||
|
result.updateableObj = this;
|
||||||
|
var querybale = this.Context.Queryable<T>().LeftJoin<T2>(joinExpress);
|
||||||
|
result.updateableObj.UpdateBuilder.JoinInfos = querybale.QueryBuilder.JoinQueryInfos;
|
||||||
|
result.updateableObj.UpdateBuilder.JoinInfos.Last().TableName = joinTable;
|
||||||
|
result.updateableObj.UpdateBuilder.ShortName = joinExpress.Parameters.FirstOrDefault()?.Name;
|
||||||
|
result.updateableObj.UpdateBuilder.TableName = tableName;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
public IUpdateable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpress,string TableName)
|
public IUpdateable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpress,string TableName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -243,6 +243,15 @@ namespace SqlSugar
|
|||||||
|
|
||||||
internal string BClassId { get; set; }
|
internal string BClassId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用于查询指定列
|
||||||
|
/// </summary>
|
||||||
|
internal string[] QueryPropertyNames { get; set; }
|
||||||
|
public string[] GetQueryPropertyNames()
|
||||||
|
{
|
||||||
|
return QueryPropertyNames;
|
||||||
|
}
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
return Name;
|
return Name;
|
||||||
@@ -272,36 +281,40 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return WhereSql;
|
return WhereSql;
|
||||||
}
|
}
|
||||||
public Navigate(NavigateType navigatType,string ifSingleMasterTableColumn_IfListChildTableColumn)
|
public Navigate(NavigateType navigatType,string ifSingleMasterTableColumn_IfListChildTableColumn, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
||||||
this.NavigatType = navigatType;
|
this.NavigatType = navigatType;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
}
|
}
|
||||||
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn)
|
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
Check.ExceptionEasy(navigatType == NavigateType.ManyToMany, "Correct usage [Navigate(typeof(ABMapping), nameof(abmapping.aid), nameof(abmapp.bid))], incorrect usage: [Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]", "多对多第一个参数是Type不是NavigateType,正确用法[Navigate(typeof(ABMapping), nameof(ABMapping.Aid), nameof(ABMapping.BId))],错误用法:[Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]");
|
Check.ExceptionEasy(navigatType == NavigateType.ManyToMany, "Correct usage [Navigate(typeof(ABMapping), nameof(abmapping.aid), nameof(abmapp.bid))], incorrect usage: [Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]", "多对多第一个参数是Type不是NavigateType,正确用法[Navigate(typeof(ABMapping), nameof(ABMapping.Aid), nameof(ABMapping.BId))],错误用法:[Navigate(Navigate.ManyToMany, nameof(ABMapping.Aid), nameof(ABMapping.BId))]");
|
||||||
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
||||||
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
|
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
|
||||||
this.NavigatType = navigatType;
|
this.NavigatType = navigatType;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string whereSql)
|
public Navigate(NavigateType navigatType, string ifSingleMasterTableColumn_IfListChildTableColumn, string ifSingleChildTableColumn_IfListMasterTableColumn, string whereSql, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
this.Name = ifSingleMasterTableColumn_IfListChildTableColumn;
|
||||||
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
|
this.Name2 = ifSingleChildTableColumn_IfListMasterTableColumn;
|
||||||
this.NavigatType = navigatType;
|
this.NavigatType = navigatType;
|
||||||
this.WhereSql = whereSql;
|
this.WhereSql = whereSql;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
//Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
|
//Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Navigate(Type MappingTableType,string typeAId,string typeBId)
|
public Navigate(Type MappingTableType,string typeAId,string typeBId, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
this.MappingType = MappingTableType;
|
this.MappingType = MappingTableType;
|
||||||
this.MappingAId = typeAId;
|
this.MappingAId = typeAId;
|
||||||
this.MappingBId = typeBId;
|
this.MappingBId = typeBId;
|
||||||
this.NavigatType = NavigateType.ManyToMany;
|
this.NavigatType = NavigateType.ManyToMany;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
}
|
}
|
||||||
public Navigate(Type MappingTableType, string mappingAId, string mappingBId,string aClassId,string bClassId)
|
public Navigate(Type MappingTableType, string mappingAId, string mappingBId,string aClassId,string bClassId, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
this.MappingType = MappingTableType;
|
this.MappingType = MappingTableType;
|
||||||
this.MappingAId = mappingAId;
|
this.MappingAId = mappingAId;
|
||||||
@@ -309,14 +322,16 @@ namespace SqlSugar
|
|||||||
this.AClassId = aClassId;
|
this.AClassId = aClassId;
|
||||||
this.BClassId = bClassId;
|
this.BClassId = bClassId;
|
||||||
this.NavigatType = NavigateType.ManyToMany;
|
this.NavigatType = NavigateType.ManyToMany;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
}
|
}
|
||||||
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql)
|
public Navigate(Type MappingTableType, string typeAiD, string typeBId,string mappingSql, string[] queryPropertyNames = null)
|
||||||
{
|
{
|
||||||
this.MappingType = MappingTableType;
|
this.MappingType = MappingTableType;
|
||||||
this.MappingAId = typeAiD;
|
this.MappingAId = typeAiD;
|
||||||
this.MappingBId = typeBId;
|
this.MappingBId = typeBId;
|
||||||
this.NavigatType = NavigateType.ManyToMany;
|
this.NavigatType = NavigateType.ManyToMany;
|
||||||
this.WhereSql+= mappingSql;
|
this.WhereSql+= mappingSql;
|
||||||
|
this.QueryPropertyNames = queryPropertyNames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ namespace SqlSugar
|
|||||||
@DateTimeOffset,
|
@DateTimeOffset,
|
||||||
@Single,
|
@Single,
|
||||||
@TimeSpan,
|
@TimeSpan,
|
||||||
@char
|
@char,
|
||||||
|
@NpgsqlBox,
|
||||||
|
@NpgsqlCircle,
|
||||||
|
@NpgsqlLine,
|
||||||
|
@NpgsqlLseg,
|
||||||
|
@NpgsqlPath,
|
||||||
|
@NpgsqlPoint,
|
||||||
|
@NpgsqlPolygon,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,19 @@ namespace SqlSugar
|
|||||||
GetTopLevelMethodCalls(lambdaExpression.Body, methodCalls);
|
GetTopLevelMethodCalls(lambdaExpression.Body, methodCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static Dictionary<string, Expression> GetNewExpressionItemListNew(Expression lamExp)
|
||||||
|
{
|
||||||
|
var caseExp = GetLambdaExpressionBody(lamExp);
|
||||||
|
caseExp = ExpressionTool.RemoveConvert(lamExp);
|
||||||
|
if (caseExp is MemberExpression c)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, Expression>() { { c.Member.Name, c } };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return GetNewExpressionItemList(lamExp);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static Dictionary<string, Expression> GetNewExpressionItemList(Expression lamExp)
|
public static Dictionary<string, Expression> GetNewExpressionItemList(Expression lamExp)
|
||||||
{
|
{
|
||||||
var caseExp = GetLambdaExpressionBody(lamExp);
|
var caseExp = GetLambdaExpressionBody(lamExp);
|
||||||
@@ -363,6 +375,12 @@ namespace SqlSugar
|
|||||||
ps.Visit(expr);
|
ps.Visit(expr);
|
||||||
return ps.Parameters;
|
return ps.Parameters;
|
||||||
}
|
}
|
||||||
|
public static bool NoParameterOrSqlfunc(Expression expr)
|
||||||
|
{
|
||||||
|
var ps = new ParameterExpressionVisitor();
|
||||||
|
ps.Visit(expr);
|
||||||
|
return ps.Parameters.Count==0&&ps.IsSqlFunc==false;
|
||||||
|
}
|
||||||
public static bool IsComparisonOperatorBool(BinaryExpression binaryExp)
|
public static bool IsComparisonOperatorBool(BinaryExpression binaryExp)
|
||||||
{
|
{
|
||||||
return binaryExp.NodeType.IsIn(ExpressionType.Equal,
|
return binaryExp.NodeType.IsIn(ExpressionType.Equal,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
internal class ParameterExpressionVisitor : ExpressionVisitor
|
internal class ParameterExpressionVisitor : ExpressionVisitor
|
||||||
{
|
{
|
||||||
|
public bool IsSqlFunc { get; set; }
|
||||||
public List<ParameterExpression> Parameters { get; } = new List<ParameterExpression>();
|
public List<ParameterExpression> Parameters { get; } = new List<ParameterExpression>();
|
||||||
|
|
||||||
protected override Expression VisitParameter(ParameterExpression node)
|
protected override Expression VisitParameter(ParameterExpression node)
|
||||||
@@ -17,6 +18,14 @@ namespace SqlSugar
|
|||||||
Parameters.Add(node);
|
Parameters.Add(node);
|
||||||
return base.VisitParameter(node);
|
return base.VisitParameter(node);
|
||||||
}
|
}
|
||||||
|
protected override Expression VisitMethodCall(MethodCallExpression node)
|
||||||
|
{
|
||||||
|
if (node.Method?.DeclaringType==typeof(SqlFunc))
|
||||||
|
{
|
||||||
|
IsSqlFunc = true;
|
||||||
|
}
|
||||||
|
return base.VisitMethodCall(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
internal class MethodCallExpressionVisitor : ExpressionVisitor
|
internal class MethodCallExpressionVisitor : ExpressionVisitor
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public partial class DefaultDbMethod : IDbMethods
|
public partial class DefaultDbMethod : IDbMethods
|
||||||
{
|
{
|
||||||
|
public ISqlSugarClient sqlSugarClient { get; set; }
|
||||||
public virtual string ParameterKeyWord { get; set; }= "@";
|
public virtual string ParameterKeyWord { get; set; }= "@";
|
||||||
public virtual string RowNumber(MethodCallExpressionModel model)
|
public virtual string RowNumber(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public interface IDbMethods
|
public interface IDbMethods
|
||||||
{
|
{
|
||||||
|
ISqlSugarClient sqlSugarClient { get; set; }
|
||||||
string IIF(MethodCallExpressionModel model);
|
string IIF(MethodCallExpressionModel model);
|
||||||
string HasNumber(MethodCallExpressionModel model);
|
string HasNumber(MethodCallExpressionModel model);
|
||||||
string HasValue(MethodCallExpressionModel model);
|
string HasValue(MethodCallExpressionModel model);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace SqlSugar
|
|||||||
express.IfFalse
|
express.IfFalse
|
||||||
};
|
};
|
||||||
SetSingleTableNameSubqueryShortName(express);
|
SetSingleTableNameSubqueryShortName(express);
|
||||||
if (ExpressionTool.GetParameters(express.Test).Count == 0)
|
if (ExpressionTool.NoParameterOrSqlfunc(express.Test))
|
||||||
{
|
{
|
||||||
while (express != null)
|
while (express != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ namespace SqlSugar
|
|||||||
result = string.Join(",",(constant.Value+"").Split(',').Select(it=>this.Context.GetTranslationTableName(it)));
|
result = string.Join(",",(constant.Value+"").Split(',').Select(it=>this.Context.GetTranslationTableName(it)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Context.DbMehtods.sqlSugarClient = this.Context?.SugarContext?.Context;
|
||||||
result = this.Context.DbMehtods.GetStringJoinSelector(result, ExpressionTool.GetExpressionValue(exp.Arguments[1]) + "");
|
result = this.Context.DbMehtods.GetStringJoinSelector(result, ExpressionTool.GetExpressionValue(exp.Arguments[1]) + "");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -304,16 +304,34 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.context.CurrentShortName=ExpressionTool.GetParameters(allMethods.FirstOrDefault()).FirstOrDefault().Name;
|
this.context.CurrentShortName=ExpressionTool.GetParameters(allMethods.FirstOrDefault()).FirstOrDefault().Name;
|
||||||
}
|
}
|
||||||
|
var hasNolock = false;
|
||||||
List<string> result = isubList.Select(it =>
|
List<string> result = isubList.Select(it =>
|
||||||
{
|
{
|
||||||
it.HasWhere = isHasWhere;
|
it.HasWhere = isHasWhere;
|
||||||
return it.GetValue(it.Expression);
|
if (it is SubWithNolock)
|
||||||
|
{
|
||||||
|
hasNolock = true;
|
||||||
|
}
|
||||||
|
var innerResult = it.GetValue(it.Expression);
|
||||||
|
var innerIsJoin = (it is SubLeftJoin || it is SubInnerJoin);
|
||||||
|
var isSqlServer =UtilMethods.GetDatabaseType(this.context) == DbType.SqlServer;
|
||||||
|
if (hasNolock && innerIsJoin&& isSqlServer)
|
||||||
|
{
|
||||||
|
innerResult = innerResult.Replace("] ON (", "] " + SqlWith.NoLock + " ON (");
|
||||||
|
}
|
||||||
|
return innerResult;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
if (this.context?.SugarContext?.Context?.CurrentConnectionConfig?.DbType == DbType.Oracle && isubList.Any(s => s is SubSelect) && isubList.Any(s => s is SubOrderBy || s is SubOrderByDesc))
|
||||||
|
{
|
||||||
|
result.Insert(0, "SELECT * FROM(");
|
||||||
|
result.Add(") WHERE ROWNUM = 1 ");
|
||||||
|
}
|
||||||
this.context.JoinIndex = 0;
|
this.context.JoinIndex = 0;
|
||||||
this.context.IsAsAttr = false;
|
this.context.IsAsAttr = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void SetOrderByIndex(List<ISubOperation> isubList)
|
private static void SetOrderByIndex(List<ISubOperation> isubList)
|
||||||
{
|
{
|
||||||
var orderByIndex = 0;
|
var orderByIndex = 0;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ namespace SqlSugar
|
|||||||
int BulkMerge(List<T> datas, string[] whereColumns);
|
int BulkMerge(List<T> datas, string[] whereColumns);
|
||||||
Task<int> BulkMergeAsync(List<T> datas, string[] whereColumns, string[] updateColumns);
|
Task<int> BulkMergeAsync(List<T> datas, string[] whereColumns, string[] updateColumns);
|
||||||
int BulkMerge(List<T> datas, string[] whereColumns, string[] updateColumns);
|
int BulkMerge(List<T> datas, string[] whereColumns, string[] updateColumns);
|
||||||
|
Task<int> BulkMergeAsync(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp);
|
||||||
|
int BulkMerge(List<T> datas, Expression<Func<T, object>> whereColumnsExp, Expression<Func<T, object>> updateColumnsExp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,65 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class UtilMethods
|
public class UtilMethods
|
||||||
{
|
{
|
||||||
|
public static bool IsArrayOrList(Type propertyType)
|
||||||
|
{
|
||||||
|
if (propertyType==null||propertyType == typeof(string))
|
||||||
|
return false;
|
||||||
|
var isList = propertyType.FullName.IsCollectionsList();
|
||||||
|
var isArray = propertyType.IsArray;
|
||||||
|
return isList || isArray;
|
||||||
|
}
|
||||||
|
public static object ConvertToArray(string input, Type targetType)
|
||||||
|
{
|
||||||
|
// 获取元素类型和集合类型
|
||||||
|
Type elementType;
|
||||||
|
bool isArray = targetType.IsArray;
|
||||||
|
bool isList = targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(List<>);
|
||||||
|
|
||||||
|
if (!isArray && !isList)
|
||||||
|
throw new ArgumentException("目标类型必须是数组或List类型");
|
||||||
|
|
||||||
|
elementType = isArray ? targetType.GetElementType() : targetType.GetGenericArguments()[0];
|
||||||
|
|
||||||
|
// 处理空输入
|
||||||
|
if (string.IsNullOrEmpty(input))
|
||||||
|
{
|
||||||
|
if (isArray)
|
||||||
|
return Array.CreateInstance(elementType, 0);
|
||||||
|
else
|
||||||
|
return Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析输入字符串
|
||||||
|
var elements = input.Trim('[', ']').Split(',');
|
||||||
|
|
||||||
|
if (isArray)
|
||||||
|
{
|
||||||
|
// 处理数组
|
||||||
|
Array array = Array.CreateInstance(elementType, elements.Length);
|
||||||
|
for (int i = 0; i < elements.Length; i++)
|
||||||
|
{
|
||||||
|
string element = elements[i]?.Trim()?.TrimStart('"')?.TrimEnd('"');
|
||||||
|
array.SetValue(UtilMethods.ChangeType2(element, elementType), i);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 处理List
|
||||||
|
var list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||||
|
for (int i = 0; i < elements.Length; i++)
|
||||||
|
{
|
||||||
|
string element = elements[i]?.Trim()?.TrimStart('"')?.TrimEnd('"');
|
||||||
|
list.Add(UtilMethods.ChangeType2(element, elementType));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal static DbType? GetDatabaseType(ExpressionContext context)
|
||||||
|
{
|
||||||
|
return context?.SugarContext?.Context?.CurrentConnectionConfig?.DbType;
|
||||||
|
}
|
||||||
internal static void SetDefaultValueForBoolean(EntityColumnInfo item, Type propertyType)
|
internal static void SetDefaultValueForBoolean(EntityColumnInfo item, Type propertyType)
|
||||||
{
|
{
|
||||||
if (propertyType == UtilConstants.BoolType && item.DefaultValue != null && item.DefaultValue.EqualCase("true"))
|
if (propertyType == UtilConstants.BoolType && item.DefaultValue != null && item.DefaultValue.EqualCase("true"))
|
||||||
|
|||||||
Reference in New Issue
Block a user