You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using SqlSugar;
|
|
|
|
namespace HighWayIot.Repository
|
|
{
|
|
public class Repository<T> : SimpleClient<T> where T : class, new()
|
|
|
|
{
|
|
public Repository(dynamic configId)
|
|
{
|
|
/**
|
|
* 根据configId动态获取数据源
|
|
*/
|
|
base.Context = SqlSugarHelper.Db.GetConnectionScope(configId);
|
|
|
|
//.NET自带IOC: base.Context = 你存储的Services.GetService<ISqlSugarClient>();
|
|
//Furion: base.Context=App.GetService<ISqlSugarClient>();
|
|
//Furion脚手架: base.Context=DbContext.Instance
|
|
//SqlSugar.Ioc: base.Context=DbScoped.SugarScope;
|
|
//手动去赋值: base.Context=DbHelper.GetDbInstance()
|
|
|
|
//动态添加
|
|
//if (!SqlSugarHelper.Db.IsAnyConnection("用户读出来的数据库ConfigId"))
|
|
//{
|
|
// SqlSugarHelper.Db.AddConnection(new ConnectionConfig() { 数据库读出来信息 });
|
|
//}
|
|
//base.Context = SqlSugarHelper.Db.GetConnectionScope("用户读出来的数据库ConfigId");
|
|
}
|
|
|
|
public SqlSugarScope _db()
|
|
{
|
|
return base.Context as SqlSugarScope;
|
|
}
|
|
}
|
|
}
|
|
|