mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update demo
This commit is contained in:
parent
a49abdcd73
commit
c099ae4bec
@ -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…
Reference in New Issue
Block a user