mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Synchronization code
This commit is contained in:
parent
1566d04389
commit
cc95ce1837
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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[] { });
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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" />
|
||||
|
@ -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);
|
||||
|
@ -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,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…
Reference in New Issue
Block a user