Browse Source

Synchronization code

pull/30/head
sunkaixuan 2 years ago
parent
commit
cc95ce1837
  1. 23
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertMethodInfo.cs
  2. 5
      Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs
  3. 46
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  4. 5
      Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs
  5. 1
      Src/Asp.Net/SqlSugar/Interface/ISqlSugarClient.cs
  6. 1
      Src/Asp.Net/SqlSugar/SqlSugar.csproj
  7. 4
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs
  8. 5
      Src/Asp.Net/SqlSugar/SqlSugarScope.cs
  9. 2
      Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec

23
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertMethodInfo.cs

@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
public class InsertMethodInfo
{
internal SqlSugarProvider Context { get; set; }
internal MethodInfo MethodInfo { get; set; }
internal object objectValue { get; set; }
public int ExecuteCommand()
{
if (Context == null) return 0;
var inertable=MethodInfo.Invoke(Context, new object[] { objectValue });
var result= inertable.GetType().GetMethod("ExecuteCommand").Invoke(inertable,new object[] { });
return (int)result;
}
}
}

5
Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/StorageableMethodInfo.cs

@ -17,6 +17,7 @@ namespace SqlSugar
if (Context == null) return 0;
object objectValue = null;
MethodInfo method = GetSaveMethod(ref objectValue);
if (method == null) return 0;
return (int)method.Invoke(objectValue, new object[] { });
}
@ -41,6 +42,7 @@ namespace SqlSugar
{
object objectValue = null;
MethodInfo method = GetSaveMethod(ref objectValue);
if (method == null) return new StorageableAsMethodInfo(null);
method = objectValue.GetType().GetMethod("ToStorage");
objectValue = method.Invoke(objectValue, new object[] { });
StorageableAsMethodInfo result = new StorageableAsMethodInfo(type);
@ -51,6 +53,8 @@ namespace SqlSugar
private MethodInfo GetSaveMethod(ref object callValue)
{
if (objectValue == null)
return null;
callValue = MethodInfo.Invoke(Context, new object[] { objectValue });
return callValue.GetType().GetMethod("ExecuteCommand");
}
@ -73,6 +77,7 @@ namespace SqlSugar
internal MethodInfo Method { get; set; }
public int ExecuteCommand()
{
if (type == null) return 0;
PropertyInfo property = ObjectValue.GetType().GetProperty(type);
var value = property.GetValue(ObjectValue);
var newObj= value.GetType().GetMethod("ExecuteCommand").Invoke(value, new object[] { });

46
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -675,6 +675,52 @@ namespace SqlSugar
#endregion
#region Insertable
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
{
if (singleEntityObjectOrListObject == null)
return new InsertMethodInfo();
if (singleEntityObjectOrListObject.GetType().FullName.IsCollectionsList())
{
var list = ((IList)singleEntityObjectOrListObject);
if (list == null || list.Count == 0)
return new InsertMethodInfo();
var type = list[0].GetType();
var newList = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
foreach (var item in list)
{
newList.Add(item);
}
var methods = this.Context.GetType().GetMethods()
.Where(it => it.Name == "Insertable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name.StartsWith("List")))
.Where(it => it.Name == "Insertable").ToList();
var method = methods.Single().MakeGenericMethod(newList.GetType().GetGenericArguments().First());
InsertMethodInfo result = new InsertMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = newList
};
return result;
}
else
{
var methods = this.Context.GetType().GetMethods()
.Where(it => it.Name == "Insertable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name == "T"))
.Where(it => it.Name == "Insertable").ToList();
var method = methods.Single().MakeGenericMethod(singleEntityObjectOrListObject.GetType());
InsertMethodInfo result = new InsertMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = singleEntityObjectOrListObject
};
return result;
}
}
public virtual IInsertable<T> Insertable<T>(T[] insertObjs) where T : class, new()
{
UtilMethods.CheckArray(insertObjs);

5
Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs

@ -215,7 +215,10 @@ namespace SqlSugar
{
ScopedContext.InitMappingInfo<T>();
}
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.InsertableByObject(singleEntityObjectOrListObject);
}
public IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
{
return ScopedContext.Insertable<T>(columnDictionary);

1
Src/Asp.Net/SqlSugar/Interface/ISqlSugarClient.cs

@ -70,6 +70,7 @@ namespace SqlSugar
IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new();
IInsertable<T> Insertable<T>(T insertObj) where T : class, new();
IInsertable<T> Insertable<T>(T[] insertObjs) where T : class, new();
InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject);
#endregion
#region Queryable

1
Src/Asp.Net/SqlSugar/SqlSugar.csproj

@ -114,6 +114,7 @@
<Compile Include="Abstract\FastestProvider\SplitFastest.cs" />
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
<Compile Include="Abstract\InsertableProvider\InsertableHelper.cs" />
<Compile Include="Abstract\InsertableProvider\InsertMethodInfo.cs" />
<Compile Include="Abstract\QueryableProvider\Entities\QueryableAppendColumn.cs" />
<Compile Include="Abstract\QueryableProvider\Entities\SqlInfo.cs" />
<Compile Include="Abstract\QueryableProvider\QueryableExecuteSqlAsync.cs" />

4
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -159,6 +159,10 @@ namespace SqlSugar
#endregion
#region Insertable
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
{
return this.Context.InsertableByObject(singleEntityObjectOrListObject);
}
public IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
{
return this.Context.Insertable<T>(columnDictionary);

5
Src/Asp.Net/SqlSugar/SqlSugarScope.cs

@ -232,7 +232,10 @@ namespace SqlSugar
{
return ScopedContext.Insertable(insertObjs);
}
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.InsertableByObject(singleEntityObjectOrListObject);
}
public void Open()
{
ScopedContext.Open();

2
Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec

@ -2,7 +2,7 @@
<package >
<metadata>
<id>SqlSugarCore</id>
<version>5.1.3.41</version>
<version>5.1.3.42-preview07</version>
<authors>sunkaixuan</authors>
<owners>果糖大数据科技</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>

Loading…
Cancel
Save