Browse Source

Update demo

pull/6/head
sunkaixuna 3 years ago
parent
commit
a49abdcd73
  1. 23
      Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs

23
Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs

@ -21,23 +21,16 @@ namespace OrmTest
{
public void Test()
{
base.db.BeginTran();
db.BeginTran();
base.GetList(); //调用内部仓储方法
base.ChangeRepository<Repository<C2Table>>().GetList();//调用外部仓储
base.db.CommitTran();
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)
{
var db = new SqlSugarClient(new List<ConnectionConfig> {
//单例实同db同上下文共享
public static SqlSugarScope db = new SqlSugarScope(new List<ConnectionConfig> {
new ConnectionConfig()
{
ConfigId="1",
@ -53,11 +46,13 @@ namespace OrmTest
ConnectionString = Config.ConnectionString2
}
});
public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
{
if (context == null)
{
var configId = typeof(T).GetCustomAttribute<TenantAttribute>().configId;
Context = db.GetConnection(configId);
this.db = db;
this.db.CodeFirst.InitTables<T>();
Context.CodeFirst.InitTables<T>();
}
}

Loading…
Cancel
Save