2. Db 静态类
📝 模块更新日志
-
新特性
-
Db.GetNewDbContext()
多个重载方法,实现类似new DbContext()
操作 4.8.8.55 ⏱️2023.11.09 4157629
-
2.1 获取非泛型仓储
var repository = Db.GetRepository();
2.2 获取泛型仓储
var entityRepository = Db.GetRepository<TEntity>();
2.3 获取带定位器泛型仓储
var locatorRepository = Db.GetRepository<TEntity, TDbContextLocator>();
2.4 获取 Sql
仓储
var sqlRepository = Db.GetSqlRepository();
2.5 获取 Sql
定位器仓储
var sqlLocatorRepository = Db.GetSqlRepository<TDbContextLocator>();
2.6 获取 Sql
代理对象
var sqlProxy= Db.GetSqlProxy<TSqlDispatchProxy>();
2.7 获取默认数据库上下文
var dbContext = Db.GetDbContext();
2.8 获取定位器数据库上下文
var locatorDbContext = Db.GetDbContext<TDbContextLocator>();
var locatorDbContext2 = Db.GetDbContext(typeof(TDbContextLocator));
2.9 创建新的默认数据库上下文
using var dbContext = Db.GetNewDbContext(); // 别忘记 using,Furion 4.8.8.55+ 版本有效
2.10 创建新的定位器数据库上下文
using var locatorDbContext = Db.GetNewDbContext<TDbContextLocator>(); // 别忘记 using,Furion 4.8.8.55+ 版本有效
using var locatorDbContext2 = Db.GetNewDbContext(typeof(TDbContextLocator)); // 别忘记 using,Furion 4.8.8.55+ 版本有效
2.11 根据定位器类型获取仓储
var repository = Db.GetRepository<TEntity>(dbContextLocatorType);
2.12 获取 主从库
仓储
var msRepository = Db.GetMSRepository();
2.13 获取 Sql
主库定位器仓储
var msLocatorRepository = Db.GetMSRepository<TMasterDbContextLocator>();
2.14 获取特定定位器仓储
var msLocatorRepository = Db.GetDbRepository<TDbContextLocator>();