mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Synchronization code
This commit is contained in:
parent
4f0b17ebfd
commit
0039a7a0fe
@ -392,6 +392,17 @@ namespace SqlSugar
|
||||
FieldValue = String.Join(",", ids),
|
||||
CSharpTypeName = navPkColumn?.UnderType?.Name
|
||||
}));
|
||||
if (OneToOneGlobalInstanceRegistry.IsAny())
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
var firstObj = navObjectNamePropety.GetValue(item);
|
||||
if (OneToOneGlobalInstanceRegistry.IsNavigationInitializerCreated(firstObj))
|
||||
{
|
||||
navObjectNamePropety.SetValue(item,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list.Any()&&navObjectNamePropety.GetValue(list.First()) == null)
|
||||
{
|
||||
var sqlObj = GetWhereSql(db,navObjectNameColumnInfo.Navigat.Name);
|
||||
|
@ -1676,6 +1676,10 @@ namespace SqlSugar
|
||||
.TrimEnd('\r')
|
||||
.TrimEnd('\n')
|
||||
.TrimEnd(';') + ";";
|
||||
if (itemSql?.StartsWith("INSERT INTO ")==true&&itemSql?.EndsWith(" returning ;") == true)
|
||||
{
|
||||
itemSql = itemSql.Replace(" returning ;", " ;");
|
||||
}
|
||||
if (itemSql == "begin;" )
|
||||
{
|
||||
itemSql = itemSql.TrimEnd(';')+"\n";
|
||||
|
@ -39,6 +39,7 @@ namespace SqlSugar
|
||||
var items=ExpressionTool.GetMemberBindingItemList(exp);
|
||||
var UpdateBuilder = updateableObj.UpdateBuilder;
|
||||
var SqlBuilder = UpdateBuilder.Builder;
|
||||
UpdateBuilder.LambdaExpressions.IsSingle = false;
|
||||
foreach (var item in items)
|
||||
{
|
||||
var dbColumnName=updateableObj.UpdateBuilder.Context.EntityMaintenance.GetDbColumnName<T>(item.Key);
|
||||
|
61
Src/Asp.Net/SqlSugar/Entities/NavigationInitializer.cs
Normal file
61
Src/Asp.Net/SqlSugar/Entities/NavigationInitializer.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Reflection.Emit;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal static class OneToOneGlobalInstanceRegistry
|
||||
{
|
||||
private static readonly Dictionary<Type, object> _instances = new Dictionary<Type, object>();
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
public static Dictionary<Type, object> Instances => _instances;
|
||||
|
||||
public static bool IsAny()
|
||||
{
|
||||
return _instances?.Count>0;
|
||||
}
|
||||
public static bool IsNavigationInitializerCreated(object instance)
|
||||
{
|
||||
if (instance == null)
|
||||
return false;
|
||||
|
||||
Type type = instance.GetType();
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
return _instances.ContainsKey(type) && _instances[type] == instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterInstance(Type type, object instance)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_instances.ContainsKey(type))
|
||||
{
|
||||
_instances[type] = instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OneToOneInitializer<T> where T : new()
|
||||
{
|
||||
public static implicit operator T(OneToOneInitializer<T> initializer)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
|
||||
if (!OneToOneGlobalInstanceRegistry.Instances.ContainsKey(type))
|
||||
{
|
||||
T instance = new T();
|
||||
OneToOneGlobalInstanceRegistry.RegisterInstance(type, instance);
|
||||
}
|
||||
|
||||
return (T)OneToOneGlobalInstanceRegistry.Instances[type];
|
||||
}
|
||||
}
|
||||
}
|
@ -166,6 +166,7 @@
|
||||
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
|
||||
<Compile Include="Abstract\UpdateProvider\UpdateNavMethodInfo.cs" />
|
||||
<Compile Include="Entities\DiscriminatorObject .cs" />
|
||||
<Compile Include="Entities\NavigationInitializer.cs" />
|
||||
<Compile Include="Entities\PropertyMetadata.cs" />
|
||||
<Compile Include="Entities\DbFastestProperties.cs" />
|
||||
<Compile Include="Entities\DefaultCustom.cs" />
|
||||
|
@ -1580,6 +1580,7 @@ namespace SqlSugar
|
||||
}
|
||||
public static string GetSqlString(ConnectionConfig connectionConfig,KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||
{
|
||||
var guid = Guid.NewGuid()+"";
|
||||
var result = sqlObj.Key;
|
||||
if (sqlObj.Value != null)
|
||||
{
|
||||
@ -1657,15 +1658,15 @@ namespace SqlSugar
|
||||
}
|
||||
else if (connectionConfig.MoreSettings?.DisableNvarchar == true || item.DbType == System.Data.DbType.AnsiString || connectionConfig.DbType == DbType.Sqlite)
|
||||
{
|
||||
result = result.Replace(item.ParameterName, $"'{item.Value.ObjToString().ToSqlFilter()}'");
|
||||
result = result.Replace(item.ParameterName, $"'{item.Value.ObjToString().Replace("@",guid).ToSqlFilter()}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result.Replace(item.ParameterName, $"N'{item.Value.ObjToString().ToSqlFilter()}'");
|
||||
result = result.Replace(item.ParameterName, $"N'{item.Value.ObjToString().Replace("@", guid).ToSqlFilter()}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = result.Replace(guid, "@");
|
||||
return result;
|
||||
}
|
||||
public static string ByteArrayToPostgreByteaLiteral(byte[] data)
|
||||
|
Loading…
Reference in New Issue
Block a user