mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 08:37:25 +08:00
Synchronization code
This commit is contained in:
parent
8f43b77b12
commit
44a15fdbfa
@ -93,6 +93,10 @@ namespace SqlSugar
|
|||||||
private InsertNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
|
private InsertNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
|
||||||
{
|
{
|
||||||
var name = ExpressionTool.GetMemberName(expression);
|
var name = ExpressionTool.GetMemberName(expression);
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
|
name =ExpressionTool.GetMemberNameByMethod(expression, name);
|
||||||
|
}
|
||||||
var isRoot = false;
|
var isRoot = false;
|
||||||
if (this._ParentEntity == null)
|
if (this._ParentEntity == null)
|
||||||
{
|
{
|
||||||
@ -121,7 +125,7 @@ namespace SqlSugar
|
|||||||
InitParentList();
|
InitParentList();
|
||||||
InsertManyToMany<TChild>(name, nav);
|
InsertManyToMany<TChild>(name, nav);
|
||||||
}
|
}
|
||||||
AddContextInfo(name,isRoot);
|
AddContextInfo(name, isRoot);
|
||||||
return GetResult<TChild>();
|
return GetResult<TChild>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -40,6 +41,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
children.AddRange(childs);
|
children.AddRange(childs);
|
||||||
}
|
}
|
||||||
|
else if (childs == null && parentNavigateProperty.PropertyInfo.GetValue(item) is IList ilist && ilist != null&& ilist.Count>0)
|
||||||
|
{
|
||||||
|
childs = GetIChildsBylList(children, thisFkColumn, parentValue, ilist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var isTreeChild = GetIsTreeChild(parentEntity, thisEntity);
|
var isTreeChild = GetIsTreeChild(parentEntity, thisEntity);
|
||||||
Check.ExceptionEasy(thisPkColumn == null, $"{thisEntity.EntityName}need primary key", $"实体{thisEntity.EntityName}需要主键");
|
Check.ExceptionEasy(thisPkColumn == null, $"{thisEntity.EntityName}need primary key", $"实体{thisEntity.EntityName}需要主键");
|
||||||
@ -54,6 +59,17 @@ namespace SqlSugar
|
|||||||
SetNewParent<TChild>(thisEntity, thisPkColumn);
|
SetNewParent<TChild>(thisEntity, thisPkColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<TChild> GetIChildsBylList<TChild>(List<TChild> children, EntityColumnInfo thisFkColumn, object parentValue, IList ilist) where TChild : class, new()
|
||||||
|
{
|
||||||
|
List<TChild> childs = ilist.Cast<TChild>().ToList();
|
||||||
|
foreach (var child in childs)
|
||||||
|
{
|
||||||
|
thisFkColumn.PropertyInfo.SetValue(child, parentValue, null);
|
||||||
|
}
|
||||||
|
children.AddRange(childs);
|
||||||
|
return childs;
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetIsTreeChild(EntityInfo parentEntity , EntityInfo thisEntity)
|
private bool GetIsTreeChild(EntityInfo parentEntity , EntityInfo thisEntity)
|
||||||
{
|
{
|
||||||
return this.NavContext?.Items?.Any() == true && parentEntity.Type == thisEntity.Type;
|
return this.NavContext?.Items?.Any() == true && parentEntity.Type == thisEntity.Type;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
@ -137,6 +138,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
children.AddRange(childs);
|
children.AddRange(childs);
|
||||||
}
|
}
|
||||||
|
else if (childs == null && parentNavigateProperty.PropertyInfo.GetValue(item) is IList ilist && ilist != null && ilist.Count > 0)
|
||||||
|
{
|
||||||
|
childs = GetIChildsBylList(children, thisFkColumn, parentValue, ilist);
|
||||||
|
}
|
||||||
ids.Add(parentValue);
|
ids.Add(parentValue);
|
||||||
if (_Options?.OneToManyNoDeleteNull == true && childs == null)
|
if (_Options?.OneToManyNoDeleteNull == true && childs == null)
|
||||||
{
|
{
|
||||||
@ -194,6 +199,16 @@ namespace SqlSugar
|
|||||||
_NavigateType = null;
|
_NavigateType = null;
|
||||||
SetNewParent<TChild>(thisEntity, thisPkColumn);
|
SetNewParent<TChild>(thisEntity, thisPkColumn);
|
||||||
}
|
}
|
||||||
|
private static List<TChild> GetIChildsBylList<TChild>(List<TChild> children, EntityColumnInfo thisFkColumn, object parentValue, IList ilist) where TChild : class, new()
|
||||||
|
{
|
||||||
|
List<TChild> childs = ilist.Cast<TChild>().ToList();
|
||||||
|
foreach (var child in childs)
|
||||||
|
{
|
||||||
|
thisFkColumn.PropertyInfo.SetValue(child, parentValue, null);
|
||||||
|
}
|
||||||
|
children.AddRange(childs);
|
||||||
|
return childs;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty)
|
private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty)
|
||||||
{
|
{
|
||||||
|
@ -97,6 +97,10 @@ namespace SqlSugar
|
|||||||
IsFirst = isRoot && this._ParentList == null;
|
IsFirst = isRoot && this._ParentList == null;
|
||||||
InitParentList();
|
InitParentList();
|
||||||
var name = ExpressionTool.GetMemberName(expression);
|
var name = ExpressionTool.GetMemberName(expression);
|
||||||
|
if (name == null)
|
||||||
|
{
|
||||||
|
name = ExpressionTool.GetMemberNameByMethod(expression, name);
|
||||||
|
}
|
||||||
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
|
||||||
if (nav.Navigat == null)
|
if (nav.Navigat == null)
|
||||||
{
|
{
|
||||||
|
@ -50,8 +50,11 @@ namespace SqlSugar
|
|||||||
case DbType.Custom:
|
case DbType.Custom:
|
||||||
className = InstanceFactory.CustomNamespace + "." + InstanceFactory.CustomDbName + "FastBuilder";
|
className = InstanceFactory.CustomNamespace + "." + InstanceFactory.CustomDbName + "FastBuilder";
|
||||||
break;
|
break;
|
||||||
|
case DbType.GaussDBNative:
|
||||||
|
className = "SqlSugar.GaussDB.GaussDBFastBuilder";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
className = $"SqlSugar.{this.context.CurrentConnectionConfig.DbType}FastBuilder";
|
className = $"SqlSugar.{this.context.CurrentConnectionConfig.DbType.ToString().Replace("Native","")}FastBuilder";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var reslut = InstanceFactory.CreateInstance<IFastBuilder>(className);
|
var reslut = InstanceFactory.CreateInstance<IFastBuilder>(className);
|
||||||
|
@ -129,7 +129,10 @@ namespace SqlSugar
|
|||||||
foreach (var item in groups)
|
foreach (var item in groups)
|
||||||
{
|
{
|
||||||
var list = item.Select(it => it.Value as T).ToList();
|
var list = item.Select(it => it.Value as T).ToList();
|
||||||
|
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataExecuting;
|
||||||
|
this.Context.Aop.DataExecuting = null;
|
||||||
var groupInserable = (InsertableProvider<T>)this.Context.Insertable<T>(list);
|
var groupInserable = (InsertableProvider<T>)this.Context.Insertable<T>(list);
|
||||||
|
this.Context.Aop.DataExecuting = dataEvent;
|
||||||
groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString;
|
groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString;
|
||||||
groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc;
|
groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc;
|
||||||
groupInserable.diffModel = parent.diffModel;
|
groupInserable.diffModel = parent.diffModel;
|
||||||
@ -150,7 +153,10 @@ namespace SqlSugar
|
|||||||
foreach (var item in groups)
|
foreach (var item in groups)
|
||||||
{
|
{
|
||||||
var list = item.Select(it => it.Value as T).ToList();
|
var list = item.Select(it => it.Value as T).ToList();
|
||||||
|
var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataExecuting;
|
||||||
|
this.Context.Aop.DataExecuting = null;
|
||||||
var groupInserable = (InsertableProvider<T>)this.Context.Insertable<T>(list);
|
var groupInserable = (InsertableProvider<T>)this.Context.Insertable<T>(list);
|
||||||
|
this.Context.Aop.DataExecuting = dataEvent;
|
||||||
groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString;
|
groupInserable.InsertBuilder.TableWithString = parent.InsertBuilder.TableWithString;
|
||||||
groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc;
|
groupInserable.RemoveCacheFunc = parent.RemoveCacheFunc;
|
||||||
groupInserable.diffModel = parent.diffModel;
|
groupInserable.diffModel = parent.diffModel;
|
||||||
|
@ -2352,7 +2352,13 @@ namespace SqlSugar
|
|||||||
var p = new SugarParameter[] {
|
var p = new SugarParameter[] {
|
||||||
new SugarParameter("@p",re.Value)
|
new SugarParameter("@p",re.Value)
|
||||||
};
|
};
|
||||||
var value = UtilMethods.GetSqlString(config.DbType, "@p", p, true);
|
var isNvarchar = true;
|
||||||
|
if (this.Context.CurrentConnectionConfig?.DbType == DbType.SqlServer
|
||||||
|
&&this.Context.CurrentConnectionConfig?.MoreSettings?.DisableNvarchar!=true)
|
||||||
|
{
|
||||||
|
isNvarchar = false;
|
||||||
|
}
|
||||||
|
var value = UtilMethods.GetSqlString(config.DbType, "@p", p, isNvarchar);
|
||||||
sql = sql.Replace(re.Name, value);
|
sql = sql.Replace(re.Name, value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Globalization;
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public partial class InsertBuilder : IDMLBuilder
|
public partial class InsertBuilder : IDMLBuilder
|
||||||
@ -266,6 +267,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return N+"'" +Convert.ToDouble(value).ToString() + "'";
|
return N+"'" +Convert.ToDouble(value).ToString() + "'";
|
||||||
}
|
}
|
||||||
|
else if (value is decimal v)
|
||||||
|
{
|
||||||
|
return v.ToString(CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return N+"'" + value.ToString() + "'";
|
return N+"'" + value.ToString() + "'";
|
||||||
|
@ -965,6 +965,11 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
result = "*";
|
result = "*";
|
||||||
}
|
}
|
||||||
|
if (result.StartsWith(UtilConstants.GroupReplaceKey))
|
||||||
|
{
|
||||||
|
this.GroupByIsReplace = true;
|
||||||
|
result = result.Replace(UtilConstants.GroupReplaceKey, string.Empty);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,6 +553,10 @@ namespace SqlSugar
|
|||||||
Check.Exception(SugarCompatible.IsFramework, "Db2 only support .net core");
|
Check.Exception(SugarCompatible.IsFramework, "Db2 only support .net core");
|
||||||
InstanceFactory.CustomDllName = "SqlSugar.Db2Core";
|
InstanceFactory.CustomDllName = "SqlSugar.Db2Core";
|
||||||
break;
|
break;
|
||||||
|
case DbType.GaussDBNative:
|
||||||
|
Check.Exception(SugarCompatible.IsFramework, "GaussDBNative only support .net core");
|
||||||
|
InstanceFactory.CustomDllName = "SqlSugar.GaussDBCore";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("ConnectionConfig.DbType is null");
|
throw new Exception("ConnectionConfig.DbType is null");
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ namespace SqlSugar
|
|||||||
TDSQL,
|
TDSQL,
|
||||||
HANA,
|
HANA,
|
||||||
DB2,
|
DB2,
|
||||||
|
GaussDBNative,
|
||||||
Custom =900
|
Custom =900
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,29 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class ExpressionTool
|
public class ExpressionTool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static string GetMemberNameByMethod(Expression expression, string name)
|
||||||
|
{
|
||||||
|
if (expression is LambdaExpression lambda)
|
||||||
|
{
|
||||||
|
if (lambda.Body is MethodCallExpression method)
|
||||||
|
{
|
||||||
|
if (method.Method.Name == "ToList")
|
||||||
|
{
|
||||||
|
if (method.Arguments.FirstOrDefault() is { } arg)
|
||||||
|
{
|
||||||
|
if (arg is MemberExpression member)
|
||||||
|
{
|
||||||
|
name = member.Member.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
internal static string ResolveMemberValue(ExpressionContext context, Expression item, string value)
|
internal static string ResolveMemberValue(ExpressionContext context, Expression item, string value)
|
||||||
{
|
{
|
||||||
if (item is MemberExpression member)
|
if (item is MemberExpression member)
|
||||||
|
@ -179,7 +179,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Context.Parameters.Add(new SugarParameter(appendValue, value));
|
var p = new SugarParameter(appendValue, value);
|
||||||
|
if (p.DbType == System.Data.DbType.String && this.Context?.SugarContext?.Context?.CurrentConnectionConfig?.MoreSettings?.DisableNvarchar == true)
|
||||||
|
{
|
||||||
|
p.DbType = System.Data.DbType.AnsiString;
|
||||||
|
}
|
||||||
|
this.Context.Parameters.Add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -444,6 +444,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return "SqlSugar.DB2."+ type+ name;
|
return "SqlSugar.DB2."+ type+ name;
|
||||||
}
|
}
|
||||||
|
else if (type == "GaussDBNative")
|
||||||
|
{
|
||||||
|
return "SqlSugar.GaussDB.GaussDB" + name;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//if (!string.IsNullOrEmpty(CustomDllName))
|
//if (!string.IsNullOrEmpty(CustomDllName))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
@ -47,13 +48,33 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var orderObj = this.SqlBuilder.GroupByModelToSql(models);
|
var orderObj = this.SqlBuilder.GroupByModelToSql(models);
|
||||||
this.GroupBy(orderObj.Key);
|
if (orderObj.Value?.Length > 0 && this.Context.CurrentConnectionConfig?.DbType == DbType.SqlServer)
|
||||||
this.QueryBuilder.Parameters.AddRange(orderObj.Value);
|
{
|
||||||
|
var groupBySql = UtilMethods.GetSqlString(DbType.SqlServer, orderObj.Key, orderObj.Value);
|
||||||
|
this.QueryBuilder.GroupBySql = groupBySql;
|
||||||
|
this.QueryBuilder.GroupBySqlOld = orderObj.Key;
|
||||||
|
this.QueryBuilder.GroupParameters = orderObj.Value.ToList();
|
||||||
|
this.GroupBy(orderObj.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.GroupBy(orderObj.Key);
|
||||||
|
this.QueryBuilder.Parameters.AddRange(orderObj.Value);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public ISugarQueryable<T> Select(List<SelectModel> models)
|
public ISugarQueryable<T> Select(List<SelectModel> models)
|
||||||
{
|
{
|
||||||
var orderObj = this.SqlBuilder.SelectModelToSql(models);
|
var orderObj = this.SqlBuilder.SelectModelToSql(models);
|
||||||
|
if (this.QueryBuilder.GroupParameters?.Any() == true && this.QueryBuilder.GroupBySql.HasValue())
|
||||||
|
{
|
||||||
|
var selectSql = UtilMethods.GetSqlString(DbType.SqlServer, orderObj.Key, UtilMethods.CopySugarParameters(orderObj.Value.ToList()).ToArray());
|
||||||
|
if (selectSql.Contains(this.QueryBuilder.GroupBySql))
|
||||||
|
{
|
||||||
|
this.Select(UtilConstants.GroupReplaceKey+selectSql);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.Select(orderObj.Key);
|
this.Select(orderObj.Key);
|
||||||
this.QueryBuilder.Parameters.AddRange(orderObj.Value);
|
this.QueryBuilder.Parameters.AddRange(orderObj.Value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -15,6 +15,7 @@ namespace SqlSugar
|
|||||||
internal const string AssemblyName = "SqlSugar";
|
internal const string AssemblyName = "SqlSugar";
|
||||||
internal static string ReplaceKey = "{"+Guid.NewGuid()+"}";
|
internal static string ReplaceKey = "{"+Guid.NewGuid()+"}";
|
||||||
internal const string ReplaceCommaKey = "{112A689B-17A1-4A06-9D27-A39EAB8BC3D5}";
|
internal const string ReplaceCommaKey = "{112A689B-17A1-4A06-9D27-A39EAB8BC3D5}";
|
||||||
|
internal const string GroupReplaceKey = "{GroupReplaceKey_l33asdysaas1231s}";
|
||||||
|
|
||||||
internal static Type UShortType = typeof(ushort);
|
internal static Type UShortType = typeof(ushort);
|
||||||
internal static Type ULongType = typeof(ulong);
|
internal static Type ULongType = typeof(ulong);
|
||||||
|
Loading…
Reference in New Issue
Block a user