mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update db.InsertableByObject
This commit is contained in:
parent
85fdec957d
commit
42f1995e58
@ -1,10 +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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -675,10 +675,51 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Insertable
|
||||
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
|
||||
public InsertMethodInfo InsertableByObject(object singleEntityObjectOrListObject)
|
||||
{
|
||||
InsertMethodInfo result = new InsertMethodInfo();
|
||||
return result;
|
||||
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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user