Browse Source

Synchronization code

pull/30/head
sunkaixuan 2 years ago
parent
commit
e1e160efcc
  1. 23
      Src/Asp.NetCore2/SqlSugar/Abstract/DeleteProvider/DeleteMethodInfo.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs
  3. 92
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  4. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs
  5. 23
      Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs
  6. 12
      Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs
  7. 9
      Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

23
Src/Asp.NetCore2/SqlSugar/Abstract/DeleteProvider/DeleteMethodInfo.cs

@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
public class DeleteMethodInfo
{
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;
}
}
}

1
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs

@ -422,7 +422,6 @@ namespace SqlSugar
InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.GBase" : "SqlSugar.GBaseCore";
break;
case DbType.Odbc:
Check.Exception(SugarCompatible.IsFramework, "Odbc only support .net core");
InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.Odbc" : "SqlSugar.OdbcCore";
break;
default:

92
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -767,6 +767,52 @@ namespace SqlSugar
#endregion
#region Deleteable
public DeleteMethodInfo DeleteableByObject(object singleEntityObjectOrListObject)
{
if (singleEntityObjectOrListObject == null)
return new DeleteMethodInfo();
if (singleEntityObjectOrListObject.GetType().FullName.IsCollectionsList())
{
var list = ((IList)singleEntityObjectOrListObject);
if (list == null || list.Count == 0)
return new DeleteMethodInfo();
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 == "Deleteable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name.StartsWith("List")))
.Where(it => it.Name == "Deleteable").ToList();
var method = methods.Single().MakeGenericMethod(newList.GetType().GetGenericArguments().FirstOrDefault());
DeleteMethodInfo result = new DeleteMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = newList
};
return result;
}
else
{
var methods = this.Context.GetType().GetMethods()
.Where(it => it.Name == "Deleteable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name == "T"))
.Where(it => it.Name == "Deleteable").ToList();
var method = methods.Single().MakeGenericMethod(singleEntityObjectOrListObject.GetType());
DeleteMethodInfo result = new DeleteMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = singleEntityObjectOrListObject
};
return result;
}
}
public virtual IDeleteable<T> Deleteable<T>() where T : class, new()
{
InitMappingInfo<T>();
@ -806,6 +852,52 @@ namespace SqlSugar
#endregion
#region Updateable
public UpdateMethodInfo UpdateableByObject(object singleEntityObjectOrListObject)
{
if (singleEntityObjectOrListObject == null)
return new UpdateMethodInfo();
if (singleEntityObjectOrListObject.GetType().FullName.IsCollectionsList())
{
var list = ((IList)singleEntityObjectOrListObject);
if (list == null || list.Count == 0)
return new UpdateMethodInfo();
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 == "Updateable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name.StartsWith("List")))
.Where(it => it.Name == "Updateable").ToList();
var method = methods.Single().MakeGenericMethod(newList.GetType().GetGenericArguments().First());
UpdateMethodInfo result = new UpdateMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = newList
};
return result;
}
else
{
var methods = this.Context.GetType().GetMethods()
.Where(it => it.Name == "Updateable")
.Where(it => it.GetGenericArguments().Any())
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name == "T"))
.Where(it => it.Name == "Updateable").ToList();
var method = methods.Single().MakeGenericMethod(singleEntityObjectOrListObject.GetType());
UpdateMethodInfo result = new UpdateMethodInfo()
{
Context = this.Context,
MethodInfo = method,
objectValue = singleEntityObjectOrListObject
};
return result;
}
}
public virtual IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new()
{
InitMappingInfo<T>();

8
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs

@ -144,6 +144,10 @@ namespace SqlSugar
{
ScopedContext.Close();
}
public DeleteMethodInfo DeleteableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.DeleteableByObject(singleEntityObjectOrListObject);
}
public IDeleteable<T> Deleteable<T>() where T : class, new()
{
return ScopedContext.Deleteable<T>();
@ -615,6 +619,10 @@ namespace SqlSugar
{
return ScopedContext.UnionAll(queryables);
}
public UpdateMethodInfo UpdateableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.UpdateableByObject(singleEntityObjectOrListObject);
}
public IUpdateable<T> Updateable<T>() where T : class, new()
{

23
Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateMethodInfo.cs

@ -0,0 +1,23 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
public class UpdateMethodInfo
{
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;
}
}
}

12
Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs

@ -181,6 +181,10 @@ namespace SqlSugar
public IInsertable<T> Insertable<T>(T insertObj) where T : class, new()
{
Check.Exception(typeof(T).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ");
if (typeof(T).Name == "Object")
{
Check.ExceptionEasy("Object type use db.InsertableByObject(obj).ExecuteCommand()", "检测到T为Object类型,请使用 db.InsertableByObject(obj).ExecuteCommand(),Insertable不支持object,InsertableByObject可以(缺点:功能比较少)");
}
return this.Context.Insertable<T>(insertObj);
}
@ -661,6 +665,10 @@ namespace SqlSugar
#endregion
#region Updateable
public UpdateMethodInfo UpdateableByObject(object singleEntityObjectOrListObject)
{
return this.Context.UpdateableByObject(singleEntityObjectOrListObject);
}
public IUpdateable<T> Updateable<T>() where T : class, new()
{
return this.Context.Updateable<T>();
@ -709,6 +717,10 @@ namespace SqlSugar
#endregion
#region Deleteable
public DeleteMethodInfo DeleteableByObject(object singleEntityObjectOrListObject)
{
return this.Context.DeleteableByObject(singleEntityObjectOrListObject);
}
public IDeleteable<T> Deleteable<T>() where T : class, new()
{
return this.Context.Deleteable<T>();

9
Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

@ -120,6 +120,10 @@ namespace SqlSugar
{
return ScopedContext.CommitTranAsync();
}
public DeleteMethodInfo DeleteableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.DeleteableByObject(singleEntityObjectOrListObject);
}
public IDeleteable<T> Deleteable<T>() where T : class, new()
{
return ScopedContext.Deleteable<T>();
@ -626,7 +630,10 @@ namespace SqlSugar
{
return ScopedContext.UnionAll(queryables);
}
public UpdateMethodInfo UpdateableByObject(object singleEntityObjectOrListObject)
{
return ScopedContext.UpdateableByObject(singleEntityObjectOrListObject);
}
public IUpdateable<T> Updateable<T>() where T : class, new()
{
return ScopedContext.Updateable<T>();

Loading…
Cancel
Save