mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-06 05:37:58 +08:00
SimpleClient.CopyNew()
This commit is contained in:
parent
6117c01e70
commit
02b13d8edc
@ -7,6 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public interface ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository;
|
||||
SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new();
|
||||
RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository ;
|
||||
IDeleteable<T> AsDeleteable();
|
||||
|
@ -35,6 +35,23 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.GetSimpleClient<ChangeType>();
|
||||
}
|
||||
public RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
|
||||
object o = null;
|
||||
if (isAnyParamter)
|
||||
{
|
||||
o = Activator.CreateInstance(type, new string[] { null });
|
||||
}
|
||||
else
|
||||
{
|
||||
o = Activator.CreateInstance(type);
|
||||
}
|
||||
var result = (RepositoryType)o;
|
||||
result.Context = this.Context.CopyNew();
|
||||
return result;
|
||||
}
|
||||
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
|
Loading…
Reference in New Issue
Block a user