mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-22 02:51:58 +08:00
Add db.GetRepository
This commit is contained in:
@@ -38,7 +38,16 @@ namespace SqlSugar
|
||||
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
|
||||
{
|
||||
Type type = typeof(RepositoryType);
|
||||
object o = Activator.CreateInstance(type,new string[]{ null});
|
||||
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;
|
||||
if (result.Context == null)
|
||||
{
|
||||
|
||||
@@ -136,6 +136,26 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.GetSimpleClient<T>();
|
||||
}
|
||||
public RepositoryType GetRepository<RepositoryType>() where RepositoryType : ISugarRepository , new()
|
||||
{
|
||||
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;
|
||||
if (result.Context == null)
|
||||
{
|
||||
result.Context = this.Context;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Insertable
|
||||
|
||||
Reference in New Issue
Block a user