/// <summary> /// 创建事务中的Db,执行后Db会被释放(用了using) /// </summary> public TRes InTran <TRes>(long id, DbTransactionContext tran, Func <T, TRes> operateFunc) { if (_dbConfig.DbConstructor.NewDbInTran == null) { throw new Exception($"{typeof(T).Name}没有定义带事务参数的构造函数,请在RegDb方法中添加设置。"); } using var db = _dbConfig.DbConstructor.NewDbInTran(Scope(DataIdBuilder.ParseDate(id)), tran); return(operateFunc(db)); }
/// <summary> /// 按Id解析时间以获取Db /// </summary> public T By(long id) { return(GetDb(Scope(DataIdBuilder.ParseDate(id)))); }