2017-08-24 15:18:53 +08:00
using System ;
using System.Collections.Generic ;
2021-12-20 14:27:20 +08:00
using System.Data ;
2021-01-31 18:44:39 +08:00
using System.Diagnostics ;
2017-08-24 15:18:53 +08:00
using System.Dynamic ;
using System.Linq ;
using System.Linq.Expressions ;
2022-04-09 12:15:28 +08:00
using System.Reflection ;
2017-08-24 15:18:53 +08:00
using System.Text ;
2019-05-17 22:26:30 +08:00
using System.Threading ;
2017-08-24 15:18:53 +08:00
using System.Threading.Tasks ;
2019-05-17 22:26:30 +08:00
2017-08-24 15:18:53 +08:00
namespace SqlSugar
{
2019-05-17 22:26:30 +08:00
public partial class SqlSugarClient : ISqlSugarClient , ITenant
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
#region Gobal Property
2019-05-20 20:51:28 +08:00
private SqlSugarProvider _Context = null ;
2019-05-17 22:26:30 +08:00
private string _ThreadId ;
private ConnectionConfig _CurrentConnectionConfig ;
private List < SugarTenant > _AllClients ;
private bool _IsAllTran = false ;
private bool _IsOpen = false ;
private MappingTableList _MappingTables ;
private MappingColumnList _MappingColumns ;
private IgnoreColumnList _IgnoreColumns ;
private IgnoreColumnList _IgnoreInsertColumns ;
2022-04-10 02:26:23 +08:00
2019-06-18 20:40:36 +08:00
internal Guid ? AsyncId { get ; set ; }
internal bool? IsSingleInstance { get ; set ; }
2019-05-17 22:26:30 +08:00
#endregion
2017-09-17 02:03:56 +08:00
2017-08-24 15:18:53 +08:00
#region Constructor
public SqlSugarClient ( ConnectionConfig config )
{
2019-05-17 22:26:30 +08:00
Check . Exception ( config = = null , "ConnectionConfig config is null" ) ;
InitContext ( config ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public SqlSugarClient ( List < ConnectionConfig > configs )
2017-08-24 15:18:53 +08:00
{
2021-10-31 17:44:48 +08:00
Check . Exception ( configs . IsNullOrEmpty ( ) , "List<ConnectionConfig> configs is null or count=0" ) ;
2019-05-17 22:26:30 +08:00
InitConfigs ( configs ) ;
var config = configs . First ( ) ;
InitContext ( config ) ;
_AllClients = configs . Select ( it = > new SugarTenant ( ) { ConnectionConfig = it } ) . ToList ( ) ; ;
_AllClients . First ( it = > it . ConnectionConfig . ConfigId = = config . ConfigId ) . Context = this . Context ;
2017-08-24 15:18:53 +08:00
}
2022-10-04 11:13:43 +08:00
public SqlSugarClient ( ConnectionConfig config , Action < SqlSugarClient > configAction )
{
Check . Exception ( config = = null , "ConnectionConfig config is null" ) ;
InitContext ( config ) ;
configAction ( this ) ;
}
2019-05-17 22:26:30 +08:00
2022-10-04 11:13:43 +08:00
public SqlSugarClient ( List < ConnectionConfig > configs , Action < SqlSugarClient > configAction )
{
Check . Exception ( configs . IsNullOrEmpty ( ) , "List<ConnectionConfig> configs is null or count=0" ) ;
InitConfigs ( configs ) ;
var config = configs . First ( ) ;
InitContext ( config ) ;
_AllClients = configs . Select ( it = > new SugarTenant ( ) { ConnectionConfig = it } ) . ToList ( ) ; ;
_AllClients . First ( it = > it . ConnectionConfig . ConfigId = = config . ConfigId ) . Context = this . Context ;
configAction ( this ) ;
}
2017-08-24 15:18:53 +08:00
#endregion
2019-05-17 22:26:30 +08:00
#region Global variable
2022-03-28 21:53:15 +08:00
public SugarActionType SugarActionType { get { return this . Context . SugarActionType ; } set { this . Context . SugarActionType = value ; } }
2019-06-01 16:30:38 +08:00
public SqlSugarProvider Context { get { return GetContext ( ) ; } }
2019-05-17 22:26:30 +08:00
public bool IsSystemTablesConfig = > this . Context . IsSystemTablesConfig ;
2019-06-01 16:30:38 +08:00
public ConnectionConfig CurrentConnectionConfig { get { return _CurrentConnectionConfig ; } set { _CurrentConnectionConfig = value ; } }
public Guid ContextID { get { return this . Context . ContextID ; } set { this . Context . ContextID = value ; } }
2021-04-25 17:31:49 +08:00
public ConfigQuery ConfigQuery { get { return this . Context . ConfigQuery ; } set { this . Context . ConfigQuery = value ; } }
2019-05-17 22:26:30 +08:00
2020-12-17 15:29:46 +08:00
public MappingTableList MappingTables { get { return _MappingTables ; } set { _MappingTables = value ; } }
2019-06-01 16:30:38 +08:00
public MappingColumnList MappingColumns { get { return _MappingColumns ; } set { _MappingColumns = value ; } }
public IgnoreColumnList IgnoreColumns { get { return _IgnoreColumns ; } set { _IgnoreColumns = value ; } }
public IgnoreColumnList IgnoreInsertColumns { get { return _IgnoreInsertColumns ; } set { _IgnoreInsertColumns = value ; } }
public Dictionary < string , object > TempItems { get { return this . Context . TempItems ; } set { this . Context . TempItems = value ; } }
2017-09-20 13:57:46 +08:00
#endregion
2019-05-17 22:26:30 +08:00
#region SimpleClient
2022-05-23 23:52:08 +08:00
public T CreateContext < T > ( bool isTran = true ) where T : SugarUnitOfWork , new ( )
{
T result = new T ( ) ;
_CreateContext ( isTran , result ) ;
var type = typeof ( T ) ;
var ps = type . GetProperties ( ) ;
var cacheKey = "SugarUnitOfWork" + typeof ( T ) . FullName + typeof ( T ) . GetHashCode ( ) ;
var properies = new ReflectionInoCacheService ( ) . GetOrCreate ( cacheKey ,
( ) = >
ps . Where ( it = >
( it . PropertyType . BaseType ! = null & & it . PropertyType . BaseType . Name . StartsWith ( "SimpleClient`" ) )
| |
it . PropertyType . Name . StartsWith ( "SimpleClient`" )
) ) ;
foreach ( var item in properies )
{
var value = Activator . CreateInstance ( item . PropertyType ) ;
2022-05-24 01:37:30 +08:00
TenantAttribute tenantAttribute = item . PropertyType . GetGenericArguments ( ) [ 0 ] . GetCustomAttribute < TenantAttribute > ( ) ;
if ( tenantAttribute = = null )
{
value . GetType ( ) . GetProperty ( "Context" ) . SetValue ( value , this ) ;
}
else
{
value . GetType ( ) . GetProperty ( "Context" ) . SetValue ( value , this . GetConnection ( tenantAttribute . configId ) ) ;
}
2022-05-23 23:52:08 +08:00
item . SetValue ( result , value ) ;
}
return result ;
}
public SugarUnitOfWork CreateContext ( bool isTran = true )
{
SugarUnitOfWork sugarUnitOf = new SugarUnitOfWork ( ) ;
return _CreateContext ( isTran , sugarUnitOf ) ;
}
private SugarUnitOfWork _CreateContext ( bool isTran , SugarUnitOfWork sugarUnitOf )
{
sugarUnitOf . Db = this ;
sugarUnitOf . Tenant = this ;
2022-05-24 01:51:38 +08:00
sugarUnitOf . IsTran = isTran ;
2022-05-23 23:52:08 +08:00
this . Open ( ) ;
if ( isTran )
this . BeginTran ( ) ;
return sugarUnitOf ;
}
2019-05-17 22:26:30 +08:00
public SimpleClient < T > GetSimpleClient < T > ( ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . GetSimpleClient < T > ( ) ;
2017-08-24 15:18:53 +08:00
}
2022-10-21 12:34:18 +08:00
public RepositoryType GetRepository < RepositoryType > ( ) where RepositoryType : ISugarRepository , new ( )
{
Type type = typeof ( RepositoryType ) ;
var isAnyParamter = type . GetConstructors ( ) . Any ( z = > z . GetParameters ( ) . Any ( ) ) ;
object o = null ;
if ( isAnyParamter )
{
o = Activator . CreateInstance ( type , new string [ ] { null } ) ;
}
else
{
o = Activator . CreateInstance ( type ) ;
}
var result = ( RepositoryType ) o ;
if ( result . Context = = null )
{
result . Context = this . Context ;
}
return result ;
}
2017-08-24 15:18:53 +08:00
#endregion
2019-05-17 22:26:30 +08:00
#region Insertable
2023-02-26 13:05:39 +08:00
public IInsertable < Dictionary < string , object > > InsertableByDynamic ( object insertDynamicObject )
{
return this . Context . InsertableByDynamic ( insertDynamicObject ) ;
}
2022-12-26 10:55:03 +08:00
public InsertMethodInfo InsertableByObject ( object singleEntityObjectOrListObject )
{
return this . Context . InsertableByObject ( singleEntityObjectOrListObject ) ;
}
2019-05-17 22:26:30 +08:00
public IInsertable < T > Insertable < T > ( Dictionary < string , object > columnDictionary ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Insertable < T > ( columnDictionary ) ;
2018-02-11 17:26:42 +08:00
}
2017-08-24 15:18:53 +08:00
2019-05-17 22:26:30 +08:00
public IInsertable < T > Insertable < T > ( dynamic insertDynamicObject ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Insertable < T > ( insertDynamicObject ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public IInsertable < T > Insertable < T > ( List < T > insertObjs ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Insertable < T > ( insertObjs ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public IInsertable < T > Insertable < T > ( T insertObj ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2021-09-05 02:55:08 +08:00
Check . Exception ( typeof ( T ) . FullName . Contains ( "System.Collections.Generic.List`" ) , " need where T: class, new() " ) ;
2022-12-26 15:34:54 +08:00
if ( typeof ( T ) . Name = = "Object" )
{
Check . ExceptionEasy ( "Object type use db.InsertableByObject(obj).ExecuteCommand()" , "检测到T为Object类型, 请使用 db.InsertableByObject(obj).ExecuteCommand(), Insertable不支持object, InsertableByObject可以(缺点:功能比较少)" ) ;
}
2019-05-17 22:26:30 +08:00
return this . Context . Insertable < T > ( insertObj ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public IInsertable < T > Insertable < T > ( T [ ] insertObjs ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Insertable < T > ( insertObjs ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
#endregion
#region Queryable
2022-06-27 22:18:07 +08:00
#region Nav CUD
2022-07-03 17:10:42 +08:00
public InsertNavTaskInit < T , T > InsertNav < T > ( T data ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
return this . Context . InsertNav ( data ) ;
}
2022-07-03 17:10:42 +08:00
public InsertNavTaskInit < T , T > InsertNav < T > ( List < T > datas ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
return this . Context . InsertNav ( datas ) ;
}
2022-10-24 14:02:40 +08:00
public InsertNavTaskInit < T , T > InsertNav < T > ( T data , InsertNavRootOptions rootOptions ) where T : class , new ( )
{
return this . Context . InsertNav ( data , rootOptions ) ;
}
public InsertNavTaskInit < T , T > InsertNav < T > ( List < T > datas , InsertNavRootOptions rootOptions ) where T : class , new ( )
{
return this . Context . InsertNav ( datas , rootOptions ) ;
}
2022-07-08 14:31:34 +08:00
public DeleteNavTaskInit < T , T > DeleteNav < T > ( T data ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
return this . Context . DeleteNav ( data ) ;
}
2022-07-08 14:31:34 +08:00
public DeleteNavTaskInit < T , T > DeleteNav < T > ( List < T > datas ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
return this . Context . DeleteNav ( datas ) ;
}
2022-07-08 14:31:34 +08:00
public DeleteNavTaskInit < T , T > DeleteNav < T > ( Expression < Func < T , bool > > whereExpression ) where T : class , new ( )
{
return this . Context . DeleteNav ( whereExpression ) ;
}
2023-05-01 14:09:35 +08:00
public DeleteNavTaskInit < T , T > DeleteNav < T > ( T data , DeleteNavRootOptions options ) where T : class , new ( )
{
return this . Context . DeleteNav ( data , options ) ;
}
public DeleteNavTaskInit < T , T > DeleteNav < T > ( List < T > datas , DeleteNavRootOptions options ) where T : class , new ( )
{
return this . Context . DeleteNav ( datas , options ) ;
}
public DeleteNavTaskInit < T , T > DeleteNav < T > ( Expression < Func < T , bool > > whereExpression , DeleteNavRootOptions options ) where T : class , new ( )
{
return this . Context . DeleteNav ( whereExpression , options ) ;
}
2022-07-16 21:46:06 +08:00
public UpdateNavTaskInit < T , T > UpdateNav < T > ( T data ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
return this . Context . UpdateNav ( data ) ;
}
2022-10-24 14:02:40 +08:00
public UpdateNavTaskInit < T , T > UpdateNav < T > ( List < T > datas , UpdateNavRootOptions rootOptions ) where T : class , new ( )
{
return this . Context . UpdateNav ( datas , rootOptions ) ;
}
public UpdateNavTaskInit < T , T > UpdateNav < T > ( T data , UpdateNavRootOptions rootOptions ) where T : class , new ( )
{
return this . Context . UpdateNav ( data , rootOptions ) ;
}
2022-07-16 21:46:06 +08:00
public UpdateNavTaskInit < T , T > UpdateNav < T > ( List < T > datas ) where T : class , new ( )
2022-06-27 22:18:07 +08:00
{
2022-10-24 14:02:40 +08:00
return this . Context . UpdateNav ( datas ) ;
2022-06-27 22:18:07 +08:00
}
#endregion
2019-05-17 22:26:30 +08:00
#region Union
public ISugarQueryable < T > Union < T > ( List < ISugarQueryable < T > > queryables ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Union ( queryables ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > Union < T > ( params ISugarQueryable < T > [ ] queryables ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Union ( queryables ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > UnionAll < T > ( List < ISugarQueryable < T > > queryables ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . UnionAll ( queryables ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > UnionAll < T > ( params ISugarQueryable < T > [ ] queryables ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . UnionAll ( queryables ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
#endregion
2022-05-12 09:15:51 +08:00
public ISugarQueryable < T > MasterQueryable < T > ( )
{
return this . Context . MasterQueryable < T > ( ) ;
}
2022-05-26 10:00:07 +08:00
public ISugarQueryable < T > SlaveQueryable < T > ( )
{
return this . Context . SlaveQueryable < T > ( ) ;
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > SqlQueryable < T > ( string sql ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SqlQueryable < T > ( sql ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < ExpandoObject > Queryable ( string tableName , string shortName )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( tableName , shortName ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 , bool > > joinExpression ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 , JoinQueryInfos > > joinExpression )
{
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 , object [ ] > > joinExpression )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , JoinQueryInfos > > joinExpression )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , bool > > joinExpression ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , object [ ] > > joinExpression )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , JoinQueryInfos > > joinExpression )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , bool > > joinExpression ) where T : class , new ( )
2019-04-28 16:08:45 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2019-04-28 16:08:45 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-11-28 13:17:18 +08:00
}
2017-08-24 15:18:53 +08:00
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 > Queryable < T , T2 , T3 , T4 , T5 , T6 , T7 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , T7 , object [ ] > > joinExpression )
2018-05-05 18:27:54 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2018-05-05 18:27:54 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 > Queryable < T , T2 , T3 , T4 , T5 , T6 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , bool > > joinExpression ) where T : class , new ( )
2018-05-05 18:27:54 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2018-05-05 18:27:54 +08:00
}
2017-08-24 15:18:53 +08:00
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 > Queryable < T , T2 , T3 , T4 , T5 , T6 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , JoinQueryInfos > > joinExpression )
2017-09-20 13:57:46 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-09-20 13:57:46 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 > Queryable < T , T2 , T3 , T4 , T5 , T6 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 > Queryable < T , T2 , T3 , T4 , T5 > ( Expression < Func < T , T2 , T3 , T4 , T5 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 > Queryable < T , T2 , T3 , T4 , T5 > ( Expression < Func < T , T2 , T3 , T4 , T5 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 , T5 > Queryable < T , T2 , T3 , T4 , T5 > ( Expression < Func < T , T2 , T3 , T4 , T5 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( Expression < Func < T , T2 , T3 , T4 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( Expression < Func < T , T2 , T3 , T4 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( Expression < Func < T , T2 , T3 , T4 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( Expression < Func < T , T2 , T3 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( Expression < Func < T , T2 , T3 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( Expression < Func < T , T2 , T3 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 > Queryable < T , T2 > ( Expression < Func < T , T2 , bool > > joinExpression ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 > Queryable < T , T2 > ( Expression < Func < T , T2 , JoinQueryInfos > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 > Queryable < T , T2 > ( Expression < Func < T , T2 , object [ ] > > joinExpression )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable ( joinExpression ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 > Queryable < T , T2 > ( ISugarQueryable < T > joinQueryable1 , ISugarQueryable < T2 > joinQueryable2 , Expression < Func < T , T2 , bool > > joinExpression )
where T : class , new ( )
where T2 : class , new ( )
2017-08-24 15:18:53 +08:00
{
2020-12-17 13:34:51 +08:00
return this . Context . Queryable ( joinQueryable1 , joinQueryable2 , joinExpression ) . With ( SqlWith . Null ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T , T2 > Queryable < T , T2 > ( ISugarQueryable < T > joinQueryable1 , ISugarQueryable < T2 > joinQueryable2 , JoinType joinType , Expression < Func < T , T2 , bool > > joinExpression )
where T : class , new ( )
where T2 : class , new ( )
2017-08-24 15:18:53 +08:00
{
2020-12-17 13:34:51 +08:00
return this . Context . Queryable ( joinQueryable1 , joinQueryable2 , joinType , joinExpression ) . With ( SqlWith . Null ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
2020-12-05 17:28:33 +08:00
2020-12-17 15:29:46 +08:00
public ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( ISugarQueryable < T > joinQueryable1 , ISugarQueryable < T2 > joinQueryable2 , ISugarQueryable < T3 > joinQueryable3 ,
JoinType joinType1 , Expression < Func < T , T2 , T3 , bool > > joinExpression1 ,
JoinType joinType2 , Expression < Func < T , T2 , T3 , bool > > joinExpression2 )
2020-12-05 17:28:33 +08:00
where T : class , new ( )
where T2 : class , new ( )
where T3 : class , new ( )
{
2020-12-17 15:29:46 +08:00
return this . Context . Queryable ( joinQueryable1 , joinQueryable2 , joinQueryable3 , joinType1 , joinExpression1 , joinType2 , joinExpression2 ) . With ( SqlWith . Null ) ;
2020-12-05 17:28:33 +08:00
}
2022-03-25 14:57:59 +08:00
public ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( ISugarQueryable < T > joinQueryable1 , ISugarQueryable < T2 > joinQueryable2 , ISugarQueryable < T3 > joinQueryable3 , ISugarQueryable < T4 > joinQueryable4 ,
JoinType joinType1 , Expression < Func < T , T2 , T3 , T4 , bool > > joinExpression1 ,
JoinType joinType2 , Expression < Func < T , T2 , T3 , T4 , bool > > joinExpression2 ,
JoinType joinType3 , Expression < Func < T , T2 , T3 , T4 , bool > > joinExpression3 )
where T : class , new ( )
where T2 : class , new ( )
where T3 : class , new ( )
where T4 : class , new ( )
{
return this . Context . Queryable ( joinQueryable1 , joinQueryable2 , joinQueryable3 , joinQueryable4 , joinType1 , joinExpression1 , joinType2 , joinExpression2 , joinType3 , joinExpression3 ) . With ( SqlWith . Null ) ;
}
2020-12-05 17:28:33 +08:00
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > Queryable < T > ( )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable < T > ( ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
2022-09-20 21:52:07 +08:00
public ISugarQueryable < T > Queryable < T > ( ISugarQueryable < T > queryable )
2017-08-24 15:18:53 +08:00
{
2021-08-07 03:42:48 +08:00
var result = this . Context . Queryable < T > ( queryable ) ;
var QueryBuilder = queryable . QueryBuilder ;
2022-04-23 22:06:38 +08:00
result . QueryBuilder . IsQueryInQuery = true ;
2022-05-07 13:25:05 +08:00
var appendIndex = result . QueryBuilder . Parameters = = null ? 1 : result . QueryBuilder . Parameters . Count + 1 ;
result . QueryBuilder . WhereIndex = ( QueryBuilder . WhereIndex + 1 ) ;
result . QueryBuilder . LambdaExpressions . ParameterIndex = ( QueryBuilder . LambdaExpressions . ParameterIndex + appendIndex ) ;
2021-08-07 03:42:48 +08:00
return result ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public ISugarQueryable < T > Queryable < T > ( string shortName )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Queryable < T > ( shortName ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
2017-08-24 15:18:53 +08:00
#endregion
2019-01-20 22:36:42 +08:00
#region Saveable
2021-12-20 14:27:20 +08:00
public StorageableDataTable Storageable ( DataTable data )
{
return this . Context . Storageable ( data ) ;
}
2022-04-30 19:03:10 +08:00
public StorageableDataTable Storageable ( List < Dictionary < string , object > > dictionaryList , string tableName )
{
DataTable dt = this . Context . Utilities . DictionaryListToDataTable ( dictionaryList ) ;
dt . TableName = tableName ;
return this . Context . Storageable ( dt ) ;
}
2022-11-04 11:11:06 +08:00
public StorageableDataTable Storageable ( Dictionary < string , object > dictionary , string tableName )
{
DataTable dt = this . Context . Utilities . DictionaryListToDataTable ( new List < Dictionary < string , object > > ( ) { dictionary } ) ;
dt . TableName = tableName ;
return this . Context . Storageable ( dt ) ;
}
2021-01-31 18:44:39 +08:00
public IStorageable < T > Storageable < T > ( List < T > dataList ) where T : class , new ( )
{
return this . Context . Storageable ( dataList ) ;
}
2021-02-04 22:35:26 +08:00
public IStorageable < T > Storageable < T > ( T data ) where T : class , new ( )
{
2021-08-31 11:52:47 +08:00
Check . Exception ( typeof ( T ) . FullName . Contains ( "System.Collections.Generic.List`" ) , " need where T: class, new() " ) ;
2021-02-04 22:35:26 +08:00
return this . Context . Storageable ( new List < T > { data } ) ;
}
2022-03-26 23:53:43 +08:00
[Obsolete("use Storageable")]
2019-04-04 23:26:32 +08:00
public ISaveable < T > Saveable < T > ( List < T > saveObjects ) where T : class , new ( )
2019-01-20 22:36:42 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Saveable < T > ( saveObjects ) ;
2019-01-20 22:36:42 +08:00
}
2022-03-26 23:53:43 +08:00
[Obsolete("use Storageable")]
2019-01-20 22:36:42 +08:00
public ISaveable < T > Saveable < T > ( T saveObject ) where T : class , new ( )
{
2019-05-17 22:26:30 +08:00
return this . Context . Saveable ( saveObject ) ;
2019-01-20 22:36:42 +08:00
}
2022-12-15 17:33:57 +08:00
public StorageableMethodInfo StorageableByObject ( object singleEntityObjectOrListObject )
{
return this . Context . StorageableByObject ( singleEntityObjectOrListObject ) ;
}
2019-01-20 22:36:42 +08:00
#endregion
2021-07-04 14:12:19 +08:00
#region Reportable
public IReportable < T > Reportable < T > ( T data )
{
return this . Context . Reportable ( data ) ;
}
public IReportable < T > Reportable < T > ( List < T > list )
{
return this . Context . Reportable ( list ) ;
}
public IReportable < T > Reportable < T > ( T [ ] array )
{
return this . Context . Reportable ( array ) ;
}
#endregion
2019-05-17 22:26:30 +08:00
#region Queue
2019-06-01 16:30:38 +08:00
public QueueList Queues { get { return this . Context . Queues ; } set { this . Context . Queues = value ; } }
2019-05-17 22:26:30 +08:00
public void AddQueue ( string sql , object parsmeters = null )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
this . Context . AddQueue ( sql , parsmeters ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public void AddQueue ( string sql , List < SugarParameter > parsmeters )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
this . Context . AddQueue ( sql , parsmeters ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public void AddQueue ( string sql , SugarParameter parsmeter )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
this . Context . AddQueue ( sql , parsmeter ) ;
}
public int SaveQueues ( bool isTran = true )
{
return this . Context . SaveQueues ( isTran ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > , List < T6 > , List < T7 > > SaveQueues < T , T2 , T3 , T4 , T5 , T6 , T7 > ( bool isTran = true )
2017-09-11 13:42:13 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 , T3 , T4 , T5 , T6 , T7 > ( isTran ) ;
2017-09-11 13:42:13 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > , List < T6 > > SaveQueues < T , T2 , T3 , T4 , T5 , T6 > ( bool isTran = true )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 , T3 , T4 , T5 , T6 > ( isTran ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > > SaveQueues < T , T2 , T3 , T4 , T5 > ( bool isTran = true )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 , T3 , T4 , T5 > ( isTran ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > > SaveQueues < T , T2 , T3 , T4 > ( bool isTran = true )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 , T3 , T4 > ( isTran ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > , List < T3 > > SaveQueues < T , T2 , T3 > ( bool isTran = true )
2018-01-23 11:24:18 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 , T3 > ( isTran ) ;
2018-01-23 11:24:18 +08:00
}
2019-05-17 22:26:30 +08:00
public Tuple < List < T > , List < T2 > > SaveQueues < T , T2 > ( bool isTran = true )
2018-01-23 11:24:18 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T , T2 > ( isTran ) ;
2018-01-23 11:24:18 +08:00
}
2017-08-24 15:18:53 +08:00
2019-05-17 22:26:30 +08:00
public List < T > SaveQueues < T > ( bool isTran = true )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueues < T > ( isTran ) ;
2017-08-24 15:18:53 +08:00
}
2019-05-17 22:26:30 +08:00
public Task < int > SaveQueuesAsync ( bool isTran = true )
2018-02-11 17:26:42 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync ( isTran ) ;
2018-02-11 17:26:42 +08:00
}
2019-05-17 22:26:30 +08:00
public Task < Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > , List < T6 > , List < T7 > > > SaveQueuesAsync < T , T2 , T3 , T4 , T5 , T6 , T7 > ( bool isTran = true )
2017-08-24 15:18:53 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync < T , T2 , T3 , T4 , T5 , T6 , T7 > ( isTran ) ;
2017-09-05 13:14:09 +08:00
}
2019-04-04 23:26:32 +08:00
2019-05-17 22:26:30 +08:00
public Task < Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > , List < T6 > > > SaveQueuesAsync < T , T2 , T3 , T4 , T5 , T6 > ( bool isTran = true )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync < T , T2 , T3 , T4 , T5 , T6 > ( isTran ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public Task < Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > , List < T5 > > > SaveQueuesAsync < T , T2 , T3 , T4 , T5 > ( bool isTran = true )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync < T , T2 , T3 , T4 , T5 > ( isTran ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public Task < Tuple < List < T > , List < T2 > , List < T3 > , List < T4 > > > SaveQueuesAsync < T , T2 , T3 , T4 > ( bool isTran = true )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync < T , T2 , T3 , T4 > ( isTran ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public Task < Tuple < List < T > , List < T2 > , List < T3 > > > SaveQueuesAsync < T , T2 , T3 > ( bool isTran = true )
{
return this . Context . SaveQueuesAsync < T , T2 , T3 > ( isTran ) ;
}
public Task < Tuple < List < T > , List < T2 > > > SaveQueuesAsync < T , T2 > ( bool isTran = true )
{
return this . Context . SaveQueuesAsync < T , T2 > ( isTran ) ;
}
2019-04-04 23:26:32 +08:00
public Task < List < T > > SaveQueuesAsync < T > ( bool isTran = true )
{
2019-05-17 22:26:30 +08:00
return this . Context . SaveQueuesAsync < T > ( isTran ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
#endregion
#region Updateable
2023-02-26 13:05:39 +08:00
public IUpdateable < Dictionary < string , object > > UpdateableByDynamic ( object updateDynamicObject )
{
return this . Context . UpdateableByDynamic ( updateDynamicObject ) ;
}
2022-12-26 15:34:54 +08:00
public UpdateMethodInfo UpdateableByObject ( object singleEntityObjectOrListObject )
{
return this . Context . UpdateableByObject ( singleEntityObjectOrListObject ) ;
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( Dictionary < string , object > columnDictionary ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( columnDictionary ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( dynamic updateDynamicObject ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( updateDynamicObject ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( Expression < Func < T , bool > > columns ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( columns ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( Expression < Func < T , T > > columns ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( columns ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( List < T > UpdateObjs ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( UpdateObjs ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( T UpdateObj ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( UpdateObj ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IUpdateable < T > Updateable < T > ( T [ ] UpdateObjs ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Updateable < T > ( UpdateObjs ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
#endregion
#region Ado
public IAdo Ado = > this . Context . Ado ;
#endregion
#region Deleteable
2022-12-26 15:34:54 +08:00
public DeleteMethodInfo DeleteableByObject ( object singleEntityObjectOrListObject )
{
return this . Context . DeleteableByObject ( singleEntityObjectOrListObject ) ;
}
2019-05-17 22:26:30 +08:00
public IDeleteable < T > Deleteable < T > ( ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Deleteable < T > ( ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IDeleteable < T > Deleteable < T > ( dynamic primaryKeyValue ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Deleteable < T > ( primaryKeyValue ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IDeleteable < T > Deleteable < T > ( dynamic [ ] primaryKeyValues ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Deleteable < T > ( primaryKeyValues ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IDeleteable < T > Deleteable < T > ( Expression < Func < T , bool > > expression ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Deleteable ( expression ) ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
public IDeleteable < T > Deleteable < T > ( List < dynamic > pkValue ) where T : class , new ( )
2019-04-04 23:26:32 +08:00
{
2019-05-17 22:26:30 +08:00
return this . Context . Deleteable < T > ( pkValue ) ;
}
public IDeleteable < T > Deleteable < T > ( List < T > deleteObjs ) where T : class , new ( )
{
return this . Context . Deleteable < T > ( deleteObjs ) ;
}
public IDeleteable < T > Deleteable < T > ( T deleteObj ) where T : class , new ( )
{
return this . Context . Deleteable < T > ( deleteObj ) ;
}
#endregion
2021-11-20 00:31:38 +08:00
#region Fastest
2021-11-18 02:42:10 +08:00
public IFastest < T > Fastest < T > ( ) where T : class , new ( )
2021-11-17 16:10:37 +08:00
{
return this . Context . Fastest < T > ( ) ;
}
#endregion
2022-04-10 02:26:23 +08:00
#region ThenMapper
public void ThenMapper < T > ( IEnumerable < T > list , Action < T > action )
{
this . Context . ThenMapper ( list , action ) ;
}
public Task ThenMapperAsync < T > ( IEnumerable < T > list , Func < T , Task > action )
{
return this . Context . ThenMapperAsync ( list , action ) ;
}
#endregion
2019-05-17 22:26:30 +08:00
#region More api
2019-06-01 16:30:38 +08:00
public IContextMethods Utilities { get { return this . Context . Utilities ; } set { this . Context . Utilities = value ; } }
2019-05-17 22:26:30 +08:00
public AopProvider Aop = > this . Context . Aop ;
public ICodeFirst CodeFirst = > this . Context . CodeFirst ;
public IDbFirst DbFirst = > this . Context . DbFirst ;
public IDbMaintenance DbMaintenance = > this . Context . DbMaintenance ;
2019-06-01 16:30:38 +08:00
public EntityMaintenance EntityMaintenance { get { return this . Context . EntityMaintenance ; } set { this . Context . EntityMaintenance = value ; } }
2020-12-17 15:29:46 +08:00
public QueryFilterProvider QueryFilter { get { return this . Context . QueryFilter ; } set { this . Context . QueryFilter = value ; } }
2019-05-17 22:26:30 +08:00
#endregion
#region TenantManager
2021-11-06 04:21:27 +08:00
public ITenant AsTenant ( )
{
var tenant = this as ITenant ;
return tenant ;
}
2021-11-20 00:31:38 +08:00
public SqlSugarTransaction UseTran ( )
2021-09-05 02:55:08 +08:00
{
2021-11-20 00:31:38 +08:00
return new SqlSugarTransaction ( this ) ;
2021-09-05 02:55:08 +08:00
}
2022-11-26 16:45:33 +08:00
public void RemoveConnection ( dynamic configId )
2022-11-25 15:50:45 +08:00
{
2022-11-26 16:45:33 +08:00
var removeData = this . _AllClients . FirstOrDefault ( it = > ( ( object ) it . ConnectionConfig . ConfigId ) . ObjToString ( ) = = ( ( object ) configId ) . ObjToString ( ) ) ;
object currentId = this . CurrentConnectionConfig . ConfigId ;
2022-11-25 15:50:45 +08:00
if ( removeData ! = null )
{
if ( removeData . Context . Ado . IsAnyTran ( ) )
{
Check . ExceptionEasy ( "RemoveConnection error has tran" , $"删除失败{removeData.ConnectionConfig.ConfigId}存在未提交事务" ) ;
}
2022-11-26 16:45:33 +08:00
else if ( ( ( object ) removeData . ConnectionConfig . ConfigId ) . ObjToString ( ) = = currentId . ObjToString ( ) )
2022-11-25 15:50:45 +08:00
{
Check . ExceptionEasy ( "Default ConfigId cannot be deleted" , $"默认库不能删除{removeData.ConnectionConfig.ConfigId}" ) ;
}
this . _AllClients . Remove ( removeData ) ;
}
}
2021-01-08 12:27:23 +08:00
public void AddConnection ( ConnectionConfig connection )
{
Check . ArgumentNullException ( connection , "AddConnection.connection can't be null" ) ;
InitTenant ( ) ;
2022-12-22 12:30:27 +08:00
var db = this . _AllClients . FirstOrDefault ( it = > ( ( object ) it . ConnectionConfig . ConfigId ) . ObjToString ( ) = = ( ( object ) connection . ConfigId ) . ObjToString ( ) ) ;
2021-01-08 12:27:23 +08:00
if ( db = = null )
{
if ( this . _AllClients = = null )
{
this . _AllClients = new List < SugarTenant > ( ) ;
}
var provider = new SqlSugarProvider ( connection ) ;
if ( connection . AopEvents ! = null )
{
provider . Ado . IsEnableLogEvent = true ;
}
this . _AllClients . Add ( new SugarTenant ( )
{
ConnectionConfig = connection ,
Context = provider
} ) ;
}
}
2022-04-09 12:15:28 +08:00
public SqlSugarProvider GetConnectionWithAttr < T > ( )
{
var attr = typeof ( T ) . GetCustomAttribute < TenantAttribute > ( ) ;
2022-04-09 17:10:34 +08:00
if ( attr = = null )
return this . GetConnection ( this . CurrentConnectionConfig . ConfigId ) ;
2022-04-09 12:15:28 +08:00
var configId = attr . configId ;
return this . GetConnection ( configId ) ;
}
2022-04-27 18:12:36 +08:00
public SqlSugarScopeProvider GetConnectionScopeWithAttr < T > ( )
{
var attr = typeof ( T ) . GetCustomAttribute < TenantAttribute > ( ) ;
if ( attr = = null )
2022-07-02 21:15:29 +08:00
return this . GetConnectionScope ( this . CurrentConnectionConfig . ConfigId ) ;
2022-04-27 18:12:36 +08:00
var configId = attr . configId ;
return this . GetConnectionScope ( configId ) ;
}
2021-01-08 12:27:23 +08:00
public SqlSugarProvider GetConnection ( dynamic configId )
{
InitTenant ( ) ;
2021-03-06 20:27:43 +08:00
var db = this . _AllClients . FirstOrDefault ( it = > Convert . ToString ( it . ConnectionConfig . ConfigId ) = = Convert . ToString ( configId ) ) ;
2021-01-08 12:27:23 +08:00
if ( db = = null )
{
Check . Exception ( true , "ConfigId was not found {0}" , configId ) ;
}
if ( db . Context = = null )
{
db . Context = new SqlSugarProvider ( db . ConnectionConfig ) ;
}
2021-03-11 11:34:15 +08:00
var intiAop = db . Context . Aop ;
2021-06-19 12:44:07 +08:00
if ( db . Context . CurrentConnectionConfig . AopEvents = = null )
{
db . Context . CurrentConnectionConfig . AopEvents = new AopEvents ( ) ;
}
2022-09-06 21:48:25 +08:00
if ( _IsAllTran & & db . Context . Ado . Transaction = = null )
{
db . Context . Ado . BeginTran ( ) ;
}
2022-10-04 20:41:09 +08:00
db . Context . Root = this ;
2021-01-08 12:27:23 +08:00
return db . Context ;
}
2022-04-27 18:12:36 +08:00
public SqlSugarScopeProvider GetConnectionScope ( dynamic configId )
{
var conn = GetConnection ( configId ) ;
return new SqlSugarScopeProvider ( conn ) ;
}
2021-08-01 17:17:09 +08:00
public bool IsAnyConnection ( dynamic configId )
{
InitTenant ( ) ;
var db = this . _AllClients . FirstOrDefault ( it = > Convert . ToString ( it . ConnectionConfig . ConfigId ) = = Convert . ToString ( configId ) ) ;
return db ! = null ;
}
2021-01-08 12:27:23 +08:00
public void ChangeDatabase ( dynamic configId )
2019-05-17 22:26:30 +08:00
{
2021-05-16 22:33:00 +08:00
configId = Convert . ToString ( configId ) ;
2020-03-31 16:02:56 +08:00
var isLog = _Context . Ado . IsEnableLogEvent ;
2021-05-16 22:33:00 +08:00
Check . Exception ( ! _AllClients . Any ( it = > Convert . ToString ( it . ConnectionConfig . ConfigId ) = = configId ) , "ConfigId was not found {0}" , configId ) ;
InitTenant ( _AllClients . First ( it = > Convert . ToString ( it . ConnectionConfig . ConfigId ) = = configId ) ) ;
2019-05-17 22:26:30 +08:00
if ( this . _IsAllTran )
this . Ado . BeginTran ( ) ;
2019-05-20 20:51:28 +08:00
if ( this . _IsOpen )
2019-05-17 22:26:30 +08:00
this . Open ( ) ;
2020-03-31 16:02:56 +08:00
_Context . Ado . IsEnableLogEvent = isLog ;
2020-12-29 23:56:46 +08:00
if ( _CurrentConnectionConfig . AopEvents = = null )
_CurrentConnectionConfig . AopEvents = new AopEvents ( ) ;
2019-05-17 22:26:30 +08:00
}
public void ChangeDatabase ( Func < ConnectionConfig , bool > changeExpression )
{
2020-03-31 16:02:56 +08:00
var isLog = _Context . Ado . IsEnableLogEvent ;
2019-05-17 22:26:30 +08:00
var allConfigs = _AllClients . Select ( it = > it . ConnectionConfig ) ;
Check . Exception ( ! allConfigs . Any ( changeExpression ) , "changeExpression was not found {0}" , changeExpression . ToString ( ) ) ;
InitTenant ( _AllClients . First ( it = > it . ConnectionConfig = = allConfigs . First ( changeExpression ) ) ) ;
if ( this . _IsAllTran )
this . Ado . BeginTran ( ) ;
if ( this . _IsOpen )
this . Open ( ) ;
2020-03-31 16:02:56 +08:00
_Context . Ado . IsEnableLogEvent = isLog ;
2020-12-29 23:56:46 +08:00
if ( _CurrentConnectionConfig . AopEvents = = null )
_CurrentConnectionConfig . AopEvents = new AopEvents ( ) ;
2019-05-17 22:26:30 +08:00
}
public void BeginTran ( )
{
_IsAllTran = true ;
2021-01-08 12:27:23 +08:00
AllClientEach ( it = > it . Ado . BeginTran ( ) ) ;
2019-05-17 22:26:30 +08:00
}
2023-01-16 10:16:37 +08:00
public void BeginTran ( IsolationLevel iso )
{
_IsAllTran = true ;
AllClientEach ( it = > it . Ado . BeginTran ( iso ) ) ;
}
2022-12-11 14:26:14 +08:00
public async Task BeginTranAsync ( )
{
_IsAllTran = true ;
await AllClientEachAsync ( async it = > await it . Ado . BeginTranAsync ( ) ) ;
}
2023-01-16 10:16:37 +08:00
public async Task BeginTranAsync ( IsolationLevel iso )
{
_IsAllTran = true ;
await AllClientEachAsync ( async it = > await it . Ado . BeginTranAsync ( iso ) ) ;
}
2022-12-11 14:26:14 +08:00
2019-05-17 22:26:30 +08:00
public void CommitTran ( )
{
this . Context . Ado . CommitTran ( ) ;
2021-09-05 02:55:08 +08:00
AllClientEach ( it = >
{
try
{
it . Ado . CommitTran ( ) ;
}
catch
{
SugarRetry . Execute ( ( ) = > it . Ado . CommitTran ( ) , new TimeSpan ( 0 , 0 , 5 ) , 3 ) ;
}
} ) ;
2019-05-17 22:26:30 +08:00
_IsAllTran = false ;
2019-04-04 23:26:32 +08:00
}
2022-12-11 14:26:14 +08:00
public async Task CommitTranAsync ( )
{
await this . Context . Ado . CommitTranAsync ( ) ;
await AllClientEachAsync ( async it = >
{
try
{
await it . Ado . CommitTranAsync ( ) ;
}
catch
{
SugarRetry . Execute ( ( ) = > it . Ado . CommitTran ( ) , new TimeSpan ( 0 , 0 , 5 ) , 3 ) ;
}
} ) ;
_IsAllTran = false ;
}
2019-05-17 22:26:30 +08:00
public DbResult < bool > UseTran ( Action action , Action < Exception > errorCallBack = null )
2019-04-10 08:25:16 +08:00
{
2019-05-17 22:26:30 +08:00
var result = new DbResult < bool > ( ) ;
try
{
this . BeginTran ( ) ;
if ( action ! = null )
action ( ) ;
this . CommitTran ( ) ;
result . Data = result . IsSuccess = true ;
}
catch ( Exception ex )
2019-04-10 08:25:16 +08:00
{
2019-05-17 22:26:30 +08:00
result . ErrorException = ex ;
result . ErrorMessage = ex . Message ;
result . IsSuccess = false ;
this . RollbackTran ( ) ;
if ( errorCallBack ! = null )
{
errorCallBack ( ex ) ;
}
2019-04-10 08:25:16 +08:00
}
2019-05-17 22:26:30 +08:00
return result ;
2019-04-10 08:25:16 +08:00
}
2019-05-17 22:26:30 +08:00
2021-08-16 21:05:11 +08:00
public async Task < DbResult < bool > > UseTranAsync ( Func < Task > action , Action < Exception > errorCallBack = null )
2019-05-17 22:26:30 +08:00
{
2021-08-16 21:05:11 +08:00
var result = new DbResult < bool > ( ) ;
try
{
2022-12-11 14:26:14 +08:00
await this . BeginTranAsync ( ) ;
2021-08-16 21:05:11 +08:00
if ( action ! = null )
await action ( ) ;
2022-12-11 14:26:14 +08:00
await this . CommitTranAsync ( ) ;
2021-08-16 21:05:11 +08:00
result . Data = result . IsSuccess = true ;
}
catch ( Exception ex )
{
result . ErrorException = ex ;
result . ErrorMessage = ex . Message ;
result . IsSuccess = false ;
2022-12-11 14:26:14 +08:00
await this . RollbackTranAsync ( ) ;
2021-08-16 21:05:11 +08:00
if ( errorCallBack ! = null )
{
errorCallBack ( ex ) ;
}
}
return result ;
2019-05-17 22:26:30 +08:00
}
public DbResult < T > UseTran < T > ( Func < T > action , Action < Exception > errorCallBack = null )
2019-04-10 08:25:16 +08:00
{
2019-05-17 22:26:30 +08:00
var result = new DbResult < T > ( ) ;
try
{
this . BeginTran ( ) ;
if ( action ! = null )
result . Data = action ( ) ;
this . CommitTran ( ) ;
result . IsSuccess = true ;
}
catch ( Exception ex )
2019-04-10 08:25:16 +08:00
{
2019-05-17 22:26:30 +08:00
result . ErrorException = ex ;
result . ErrorMessage = ex . Message ;
result . IsSuccess = false ;
this . RollbackTran ( ) ;
if ( errorCallBack ! = null )
{
errorCallBack ( ex ) ;
}
2019-04-10 08:25:16 +08:00
}
2019-05-17 22:26:30 +08:00
return result ;
2019-04-10 08:25:16 +08:00
}
2019-04-04 23:26:32 +08:00
2021-08-16 21:05:11 +08:00
public async Task < DbResult < T > > UseTranAsync < T > ( Func < Task < T > > action , Action < Exception > errorCallBack = null )
2019-04-04 23:26:32 +08:00
{
2021-08-16 21:05:11 +08:00
var result = new DbResult < T > ( ) ;
try
{
this . BeginTran ( ) ;
T data = default ( T ) ;
if ( action ! = null )
data = await action ( ) ;
this . CommitTran ( ) ;
2021-09-05 02:55:08 +08:00
result . IsSuccess = true ;
2021-08-16 21:05:11 +08:00
result . Data = data ;
}
catch ( Exception ex )
{
result . ErrorException = ex ;
result . ErrorMessage = ex . Message ;
result . IsSuccess = false ;
this . RollbackTran ( ) ;
if ( errorCallBack ! = null )
{
errorCallBack ( ex ) ;
}
}
return result ;
2019-05-17 22:26:30 +08:00
}
public void RollbackTran ( )
{
this . Context . Ado . RollbackTran ( ) ;
2021-09-05 02:55:08 +08:00
AllClientEach ( it = >
{
try
{
it . Ado . RollbackTran ( ) ;
}
catch
{
SugarRetry . Execute ( ( ) = > it . Ado . RollbackTran ( ) , new TimeSpan ( 0 , 0 , 5 ) , 3 ) ;
}
} ) ;
2019-05-17 22:26:30 +08:00
_IsAllTran = false ;
}
2022-12-11 14:26:14 +08:00
public async Task RollbackTranAsync ( )
{
await this . Context . Ado . RollbackTranAsync ( ) ;
await AllClientEachAsync ( async it = >
{
try
{
await it . Ado . RollbackTranAsync ( ) ;
}
catch
{
SugarRetry . Execute ( ( ) = > it . Ado . RollbackTran ( ) , new TimeSpan ( 0 , 0 , 5 ) , 3 ) ;
}
} ) ;
_IsAllTran = false ;
}
2019-05-17 22:26:30 +08:00
public void Close ( )
{
this . Context . Close ( ) ;
AllClientEach ( it = > it . Close ( ) ) ;
_IsOpen = false ;
}
public void Open ( )
{
this . Context . Open ( ) ;
_IsOpen = true ;
}
#endregion
#region IDispose
public void Dispose ( )
{
AllClientEach ( it = > it . Ado . RollbackTran ( ) ) ;
2022-02-16 10:18:58 +08:00
AllClientEach ( it = > it . Dispose ( ) ) ;
2019-05-17 22:26:30 +08:00
}
#endregion
2021-03-27 15:46:11 +08:00
#region Cache
public SugarCacheProvider DataCache
{
get { return this . Context . DataCache ; }
}
#endregion
2019-05-17 22:26:30 +08:00
#region Other method
2023-03-21 15:58:43 +08:00
public DynamicBuilder DynamicBuilder ( )
{
return this . Context . DynamicBuilder ( ) ;
}
2022-08-02 10:04:16 +08:00
public void Tracking < T > ( T data ) where T : class , new ( )
{
this . Context . Tracking ( data ) ;
}
public void Tracking < T > ( List < T > datas ) where T : class , new ( )
{
this . Context . Tracking ( datas ) ;
}
2022-08-01 16:42:08 +08:00
public SqlSugarClient CopyNew ( )
{
2022-11-08 22:30:48 +08:00
var result = new SqlSugarClient ( UtilMethods . CopyConfig ( this . Ado . Context . CurrentConnectionConfig ) ) ;
result . QueryFilter = this . QueryFilter ;
return result ;
2022-08-01 16:42:08 +08:00
}
2019-05-17 22:26:30 +08:00
public DateTime GetDate ( )
{
return this . Context . GetDate ( ) ;
}
public void InitMappingInfo ( Type type )
{
this . Context . InitMappingInfo ( type ) ;
}
public void InitMappingInfo < T > ( )
{
this . Context . InitMappingInfo ( typeof ( T ) ) ;
}
#endregion
#region Helper
2023-04-15 08:33:02 +08:00
public Task < SugarAsyncLock > AsyncLock ( int timeOutSeconds = 30 )
{
return this . Context . AsyncLock ( timeOutSeconds ) ;
}
2021-10-31 17:44:48 +08:00
public SplitTableContext SplitHelper < T > ( ) where T : class , new ( )
{
return this . Context . SplitHelper < T > ( ) ;
}
2023-02-08 12:42:37 +08:00
public SplitTableContext SplitHelper ( Type entityType )
{
2023-02-08 12:44:12 +08:00
return this . Context . SplitHelper ( entityType ) ;
2023-02-08 12:42:37 +08:00
}
2021-10-31 17:44:48 +08:00
public SplitTableContextResult < T > SplitHelper < T > ( T data ) where T : class , new ( )
{
return this . Context . SplitHelper ( data ) ;
}
public SplitTableContextResult < T > SplitHelper < T > ( List < T > dataList ) where T : class , new ( )
{
return this . Context . SplitHelper ( dataList ) ;
}
2019-05-20 20:51:28 +08:00
private SqlSugarProvider GetContext ( )
{
2019-06-18 20:40:36 +08:00
SqlSugarProvider result = null ;
2021-10-31 17:44:48 +08:00
//if (IsSameThreadAndShard())
//{
// result = SameThreadAndShard();
//}
//else if (IsNoSameThreadAndShard())
//{
// result = NoSameThreadAndShard();
//}
//else
//{
2019-06-18 20:40:36 +08:00
result = Synchronization ( ) ;
2021-10-31 17:44:48 +08:00
//}
2021-08-16 23:12:48 +08:00
///Because SqlSugarScope implements thread safety
//else if (IsSingleInstanceAsync())
//{
// result = Synchronization();//Async no support Single Instance
//}
//else if (IsAsync())
//{
// result = Synchronization();
//}
//else
//{
// StackTrace st = new StackTrace(true);
// var methods = st.GetFrames();
// var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
// if (isAsync)
// {
// result = Synchronization();
// }
// else
// {
// result = NoSameThread();
// }
//}
2019-06-18 20:40:36 +08:00
if ( result . Root = = null )
{
result . Root = this ;
}
return result ;
2019-05-20 20:51:28 +08:00
}
2019-06-18 20:40:36 +08:00
private SqlSugarProvider NoSameThreadAsync ( )
{
var result = GetCallContext ( ) ;
return result ;
}
2019-05-20 20:51:28 +08:00
private SqlSugarProvider NoSameThread ( )
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
if ( CallContext . ContextList . Value = = null )
2019-04-04 23:26:32 +08:00
{
2019-05-20 20:51:28 +08:00
var context = CopyClient ( ) ;
AddCallContext ( context ) ;
return context ;
}
else
{
var result = GetCallContext ( ) ;
if ( result = = null )
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
var copy = CopyClient ( ) ;
AddCallContext ( copy ) ;
return copy ;
2019-04-04 23:26:32 +08:00
}
2019-05-17 22:26:30 +08:00
else
2019-04-04 23:26:32 +08:00
{
2019-05-20 20:51:28 +08:00
return result ;
2019-04-04 23:26:32 +08:00
}
}
2019-05-20 20:51:28 +08:00
}
2021-01-08 12:27:23 +08:00
private void InitTenant ( )
{
if ( this . _AllClients = = null )
{
this . _AllClients = new List < SugarTenant > ( ) ;
this . _AllClients . Add ( new SugarTenant ( )
{
ConnectionConfig = this . CurrentConnectionConfig ,
Context = this . Context
} ) ;
}
}
2019-05-20 20:51:28 +08:00
private SqlSugarProvider Synchronization ( )
{
_Context . MappingColumns = _MappingColumns ;
_Context . MappingTables = _MappingTables ;
_Context . IgnoreColumns = _IgnoreColumns ;
_Context . IgnoreInsertColumns = _IgnoreInsertColumns ;
return _Context ;
}
private SqlSugarProvider NoSameThreadAndShard ( )
{
if ( CallContext . ContextList . Value . IsNullOrEmpty ( ) )
2019-04-04 23:26:32 +08:00
{
2019-05-20 20:51:28 +08:00
var copy = CopyClient ( ) ;
AddCallContext ( copy ) ;
return copy ;
2019-05-17 22:26:30 +08:00
}
else
{
2019-05-20 20:51:28 +08:00
var result = GetCallContext ( ) ;
if ( result = = null )
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
var copy = CopyClient ( ) ;
AddCallContext ( copy ) ;
return copy ;
2019-05-17 22:26:30 +08:00
}
2019-05-20 20:51:28 +08:00
else
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
return result ;
}
}
}
private SqlSugarProvider SameThreadAndShard ( )
{
if ( CallContext . ContextList . Value . IsNullOrEmpty ( ) )
{
AddCallContext ( _Context ) ;
return _Context ;
}
else
{
var result = GetCallContext ( ) ;
if ( result = = null )
{
var copy = CopyClient ( ) ;
AddCallContext ( copy ) ;
return copy ;
2019-05-17 22:26:30 +08:00
}
else
{
2019-05-20 20:51:28 +08:00
return result ;
2019-05-17 22:26:30 +08:00
}
}
}
2019-06-18 20:40:36 +08:00
private bool IsAsync ( )
{
return AsyncId ! = null ;
}
private bool IsSingleInstanceAsync ( )
{
return IsSingleInstance = = true & & AsyncId ! = null ;
}
2019-05-20 20:51:28 +08:00
private bool IsSynchronization ( )
{
return _ThreadId = = Thread . CurrentThread . ManagedThreadId . ToString ( ) ;
}
2021-10-31 17:44:48 +08:00
//private bool IsNoSameThreadAndShard()
//{
// return CurrentConnectionConfig.IsShardSameThread && _ThreadId != Thread.CurrentThread.ManagedThreadId.ToString();
//}
2019-05-20 20:51:28 +08:00
2021-10-31 17:44:48 +08:00
//private bool IsSameThreadAndShard()
//{
// return CurrentConnectionConfig.IsShardSameThread && _ThreadId == Thread.CurrentThread.ManagedThreadId.ToString();
//}
2019-05-20 20:51:28 +08:00
private SqlSugarProvider CopyClient ( )
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
var result = new SqlSugarProvider ( this . CurrentConnectionConfig ) ;
2019-05-17 22:26:30 +08:00
result . MappingColumns = _MappingColumns ;
result . MappingTables = _MappingTables ;
result . IgnoreColumns = _IgnoreColumns ;
result . IgnoreInsertColumns = _IgnoreInsertColumns ;
2019-05-20 20:51:28 +08:00
2019-05-17 22:26:30 +08:00
return result ;
}
2019-05-20 20:51:28 +08:00
private void AddCallContext ( SqlSugarProvider context )
{
CallContext . ContextList . Value = new List < SqlSugarProvider > ( ) ;
CallContext . ContextList . Value . Add ( context ) ;
}
2019-05-17 22:26:30 +08:00
2019-05-20 20:51:28 +08:00
private SqlSugarProvider GetCallContext ( )
2019-05-17 22:26:30 +08:00
{
2019-05-20 20:51:28 +08:00
return CallContext . ContextList . Value . FirstOrDefault ( it = >
it . CurrentConnectionConfig . DbType = = _Context . CurrentConnectionConfig . DbType & &
it . CurrentConnectionConfig . ConnectionString = = _Context . CurrentConnectionConfig . ConnectionString & &
it . CurrentConnectionConfig . InitKeyType = = _Context . CurrentConnectionConfig . InitKeyType & &
it . CurrentConnectionConfig . IsAutoCloseConnection = = _Context . CurrentConnectionConfig . IsAutoCloseConnection
2019-05-17 22:26:30 +08:00
) ;
}
2022-12-11 22:22:56 +08:00
protected virtual void InitContext ( ConnectionConfig config )
2019-05-17 22:26:30 +08:00
{
var aopIsNull = config . AopEvents = = null ;
if ( aopIsNull )
{
config . AopEvents = new AopEvents ( ) ;
}
_Context = new SqlSugarProvider ( config ) ;
if ( ! aopIsNull )
_Context . Ado . IsEnableLogEvent = true ;
this . CurrentConnectionConfig = config ;
_ThreadId = Thread . CurrentThread . ManagedThreadId . ToString ( ) ;
2021-10-31 17:44:48 +08:00
if ( this . MappingTables = = null )
2019-05-17 22:26:30 +08:00
this . MappingTables = new MappingTableList ( ) ;
if ( this . MappingColumns = = null )
this . MappingColumns = new MappingColumnList ( ) ;
if ( this . IgnoreColumns = = null )
this . IgnoreColumns = new IgnoreColumnList ( ) ;
if ( this . IgnoreInsertColumns = = null )
this . IgnoreInsertColumns = new IgnoreColumnList ( ) ;
}
private void InitConfigs ( List < ConnectionConfig > configs )
{
foreach ( var item in configs )
{
if ( item . ConfigId = = null )
{
item . ConfigId = Guid . NewGuid ( ) . ToString ( ) ;
}
}
}
private void AllClientEach ( Action < ISqlSugarClient > action )
{
2021-01-17 02:50:01 +08:00
if ( this . _AllClients = = null )
{
this . _AllClients = new List < SugarTenant > ( ) ;
this . _AllClients . Add ( new SugarTenant ( ) { ConnectionConfig = this . CurrentConnectionConfig , Context = this . Context } ) ;
}
2019-05-17 22:26:30 +08:00
if ( _AllClients . HasValue ( ) )
{
foreach ( var item in _AllClients . Where ( it = > it . Context . HasValue ( ) ) )
{
action ( item . Context ) ;
}
2019-04-04 23:26:32 +08:00
}
}
2022-12-11 14:26:14 +08:00
private async Task AllClientEachAsync ( Func < ISqlSugarClient , Task > action )
{
if ( this . _AllClients = = null )
{
this . _AllClients = new List < SugarTenant > ( ) ;
this . _AllClients . Add ( new SugarTenant ( ) { ConnectionConfig = this . CurrentConnectionConfig , Context = this . Context } ) ;
}
if ( _AllClients . HasValue ( ) )
{
foreach ( var item in _AllClients . Where ( it = > it . Context . HasValue ( ) ) )
{
await action ( item . Context ) ;
}
}
}
2019-05-17 22:26:30 +08:00
private void InitTenant ( SugarTenant Tenant )
{
if ( Tenant . Context = = null )
{
2019-05-20 20:51:28 +08:00
Tenant . Context = new SqlSugarProvider ( Tenant . ConnectionConfig ) ;
2019-05-17 22:26:30 +08:00
}
_Context = Tenant . Context ;
this . CurrentConnectionConfig = Tenant . ConnectionConfig ;
}
#endregion
2022-06-15 22:16:55 +08:00
#region Tenant Crud
public ISugarQueryable < T > QueryableWithAttr < T > ( )
{
2022-10-05 10:47:06 +08:00
var result = this . GetConnectionWithAttr < T > ( ) . Queryable < T > ( ) ;
result . QueryBuilder . IsCrossQueryWithAttr = true ;
return result ;
2022-06-15 22:16:55 +08:00
}
public IInsertable < T > InsertableWithAttr < T > ( T insertObj ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Insertable ( insertObj ) ;
}
public IInsertable < T > InsertableWithAttr < T > ( List < T > insertObjs ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Insertable ( insertObjs ) ;
}
public IUpdateable < T > UpdateableWithAttr < T > ( T updateObj ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Updateable ( updateObj ) ;
}
2022-06-29 14:06:18 +08:00
public IUpdateable < T > UpdateableWithAttr < T > ( ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Updateable < T > ( ) ;
}
2022-06-15 22:16:55 +08:00
public IUpdateable < T > UpdateableWithAttr < T > ( List < T > updateObjs ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Updateable ( updateObjs ) ;
}
public IDeleteable < T > DeleteableWithAttr < T > ( T deleteObject ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Deleteable ( deleteObject ) ;
}
2022-06-30 14:22:38 +08:00
public IDeleteable < T > DeleteableWithAttr < T > ( ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Deleteable < T > ( ) ;
}
2022-06-15 22:16:55 +08:00
public IDeleteable < T > DeleteableWithAttr < T > ( List < T > deleteObjects ) where T : class , new ( )
{
return this . GetConnectionWithAttr < T > ( ) . Deleteable ( deleteObjects ) ;
}
#endregion
2017-08-24 15:18:53 +08:00
}
}