Update demo

This commit is contained in:
sunkaixuna
2021-07-04 14:25:21 +08:00
parent 8ff5ac17fb
commit e9e497db75
4 changed files with 236 additions and 6 deletions

View File

@@ -21,18 +21,19 @@ namespace OrmTest
{
public void Test()
{
base.AsTenant().BeginTran();
base.db.BeginTran();
base.GetList(); //调用内部仓储方法
base.ChangeRepository<Repository<C2Table>>().GetList();//调用外部仓储
base.AsTenant().CommitTran();
base.db.CommitTran();
}
}
public class Repository<T> : SimpleClient<T> where T : class, new()
{
public SqlSugarClient db;
public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
{
if (context == null)
@@ -53,10 +54,10 @@ namespace OrmTest
ConnectionString = Config.ConnectionString2
}
});
base.Context = db;
var configId = typeof(T).GetCustomAttribute<TenantAttribute>().configId;
db.ChangeDatabase(configId);
Context = db.GetConnection(configId);
this.db = db;
}
}