2017-08-24 15:18:53 +08:00
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Dynamic ;
using System.Linq ;
using System.Linq.Expressions ;
using System.Text ;
using System.Threading.Tasks ;
namespace SqlSugar
{
///<summary>
/// ** description: Create database access object
/// ** author: sunkaixuan
/// ** date: 2017/1/2
/// ** email:610262374@qq.com
/// </summary>
public partial class SqlSugarClient : SqlSugarAccessory , IDisposable
{
2017-09-17 02:03:56 +08:00
2017-08-24 15:18:53 +08:00
#region Constructor
public SqlSugarClient ( ConnectionConfig config )
{
base . Context = this ;
base . CurrentConnectionConfig = config ;
2017-10-28 13:33:07 +08:00
base . ContextID = Guid . NewGuid ( ) ;
2017-09-17 02:03:56 +08:00
Check . ArgumentNullException ( config , "config is null" ) ;
switch ( config . DbType )
2017-08-28 02:31:02 +08:00
{
2017-09-17 02:03:56 +08:00
case DbType . MySql :
DependencyManagement . TryMySqlData ( ) ;
break ;
case DbType . SqlServer :
break ;
case DbType . Sqlite :
DependencyManagement . TrySqlite ( ) ;
break ;
case DbType . Oracle :
2017-10-23 15:26:24 +08:00
DependencyManagement . TryOracle ( ) ;
break ;
2018-01-15 12:56:56 +08:00
case DbType . PostgreSQL :
throw new Exception ( "Development 50%" ) ;
2017-09-17 02:03:56 +08:00
default :
throw new Exception ( "ConnectionConfig.DbType is null" ) ;
2017-08-28 02:31:02 +08:00
}
2017-08-24 15:18:53 +08:00
}
#endregion
#region ADO Methods
/// <summary>
///Database operation
/// </summary>
public virtual IAdo Ado
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _Ado = = null )
2017-08-24 15:18:53 +08:00
{
2017-10-28 13:33:07 +08:00
var reval = InstanceFactory . GetAdo ( base . Context . CurrentConnectionConfig ) ;
base . Context . _Ado = reval ;
reval . Context = base . Context ;
2017-08-24 15:18:53 +08:00
return reval ;
}
2017-10-28 13:33:07 +08:00
return base . Context . _Ado ;
2017-08-24 15:18:53 +08:00
}
}
#endregion
2017-09-20 13:57:46 +08:00
#region Aop Log Methods
2017-10-28 13:33:07 +08:00
public virtual AopProvider Aop { get { return new AopProvider ( base . Context ) ; } }
2017-09-20 13:57:46 +08:00
#endregion
2017-09-11 13:42:13 +08:00
#region Util Methods
[Obsolete("Use SqlSugarClient.Utilities")]
2017-10-23 15:26:24 +08:00
public virtual IContextMethods RewritableMethods
2017-09-11 13:42:13 +08:00
{
2017-10-28 13:33:07 +08:00
get { return base . Context . Utilities ; }
set { base . Context . Utilities = value ; }
2017-09-11 13:42:13 +08:00
}
2017-10-23 15:26:24 +08:00
public virtual IContextMethods Utilities
2017-08-24 15:18:53 +08:00
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _RewritableMethods = = null )
2017-10-23 15:26:24 +08:00
{
2017-10-28 13:33:07 +08:00
base . Context . _RewritableMethods = new ContextMethods ( ) ;
base . Context . _RewritableMethods . Context = base . Context ;
2017-10-23 15:26:24 +08:00
}
2017-10-28 13:33:07 +08:00
return base . Context . _RewritableMethods ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
set { base . Context . _RewritableMethods = value ; }
2017-08-24 15:18:53 +08:00
}
#endregion
#region Queryable
/// <summary>
/// Lambda Query operation
/// </summary>
public virtual ISugarQueryable < T > Queryable < T > ( ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
var result = base . CreateQueryable < T > ( ) ;
return result ;
}
/// <summary>
/// Lambda Query operation
/// </summary>
public virtual ISugarQueryable < T > Queryable < T > ( string shortName ) where T : class , new ( )
{
var queryable = Queryable < T > ( ) ;
queryable . SqlBuilder . QueryBuilder . TableShortName = shortName ;
return queryable ;
}
/// <summary>
/// Lambda Query operation
/// </summary>
public virtual ISugarQueryable < ExpandoObject > Queryable ( string tableName , string shortName )
{
var queryable = Queryable < ExpandoObject > ( ) ;
queryable . SqlBuilder . QueryBuilder . EntityName = tableName ;
queryable . SqlBuilder . QueryBuilder . TableShortName = shortName ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 > Queryable < T , T2 > ( Expression < Func < T , T2 , object [ ] > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( Expression < Func < T , T2 , T3 , object [ ] > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( Expression < Func < T , T2 , T3 , T4 , object [ ] > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 , T4 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 , T4 , T5 > Queryable < T , T2 , T3 , T4 , T5 > ( Expression < Func < T , T2 , T3 , T4 , T5 , object [ ] > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 , T4 , T5 , T6 > Queryable < T , T2 , T3 , T4 , T5 , T6 > ( Expression < Func < T , T2 , T3 , T4 , T5 , T6 , object [ ] > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
#region 9 - 12
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) , typeof ( T11 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
public virtual 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 ) where T : class , new ( )
{
2017-09-11 13:42:13 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( ) ;
2017-08-24 15:18:53 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) , typeof ( T11 ) , typeof ( T12 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( base . CurrentConnectionConfig ) ;
base . CreateQueryJoin ( joinExpression , types , queryable ) ;
return queryable ;
}
#endregion
public virtual ISugarQueryable < T , T2 > Queryable < T , T2 > ( Expression < Func < T , T2 , bool > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 > Queryable < T , T2 , T3 > ( Expression < Func < T , T2 , T3 , bool > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual ISugarQueryable < T , T2 , T3 , T4 > Queryable < T , T2 , T3 , T4 > ( Expression < Func < T , T2 , T3 , T4 , bool > > joinExpression ) where T : class , new ( )
{
InitMppingInfo < T , T2 , T3 , T4 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual 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 ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual 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 ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual 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 ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
public virtual 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 ( )
{
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T8 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
#region 9 - 12
2017-08-28 02:31:02 +08:00
public virtual 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
{
2017-08-28 02:31:02 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T8 , T9 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > ( base . CurrentConnectionConfig ) ;
2017-08-24 15:18:53 +08:00
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
2017-08-28 02:31:02 +08:00
public virtual 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 ( )
2017-08-24 15:18:53 +08:00
{
2017-08-28 02:31:02 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T8 , T9 , T10 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > ( base . CurrentConnectionConfig ) ;
2017-08-24 15:18:53 +08:00
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
2017-08-28 02:31:02 +08:00
public virtual 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
{
2017-08-28 02:31:02 +08:00
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T8 , T9 , T10 , T11 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) , typeof ( T11 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 > ( base . CurrentConnectionConfig ) ;
2017-08-24 15:18:53 +08:00
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
2017-08-28 02:31:02 +08:00
public virtual 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 ( )
2017-08-24 15:18:53 +08:00
{
InitMppingInfo < T , T2 , T3 , T4 , T5 , T6 , T8 , T9 , T10 , T11 , T12 > ( ) ;
2017-08-28 02:31:02 +08:00
var types = new Type [ ] { typeof ( T2 ) , typeof ( T3 ) , typeof ( T4 ) , typeof ( T5 ) , typeof ( T6 ) , typeof ( T7 ) , typeof ( T8 ) , typeof ( T9 ) , typeof ( T10 ) , typeof ( T11 ) , typeof ( T12 ) } ;
2017-08-24 15:18:53 +08:00
var queryable = InstanceFactory . GetQueryable < T , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , T11 , T12 > ( base . CurrentConnectionConfig ) ;
base . CreateEasyQueryJoin ( joinExpression , types , queryable ) ;
queryable . Where ( joinExpression ) ;
return queryable ;
}
2017-11-28 13:17:18 +08:00
public virtual 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 ( )
{
return Queryable ( joinQueryable1 , joinQueryable2 , JoinType . Inner , joinExpression ) ;
}
public virtual 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 ( )
{
Check . Exception ( joinQueryable1 . QueryBuilder . Take ! = null | | joinQueryable1 . QueryBuilder . Skip ! = null | | joinQueryable1 . QueryBuilder . OrderByValue . HasValue ( ) , "joinQueryable1 Cannot have 'Skip' 'ToPageList' 'Take' Or 'OrderBy'" ) ;
Check . Exception ( joinQueryable2 . QueryBuilder . Take ! = null | | joinQueryable2 . QueryBuilder . Skip ! = null | | joinQueryable2 . QueryBuilder . OrderByValue . HasValue ( ) , "joinQueryable2 Cannot have 'Skip' 'ToPageList' 'Take' Or 'OrderBy'" ) ;
var sqlBuilder = InstanceFactory . GetSqlbuilder ( base . Context . CurrentConnectionConfig ) ;
sqlBuilder . Context = base . Context ;
InitMppingInfo < T , T2 > ( ) ;
var types = new Type [ ] { typeof ( T2 ) } ;
var queryable = InstanceFactory . GetQueryable < T , T2 > ( base . CurrentConnectionConfig ) ;
queryable . Context = base . Context ;
queryable . SqlBuilder = sqlBuilder ;
queryable . QueryBuilder = InstanceFactory . GetQueryBuilder ( base . CurrentConnectionConfig ) ;
queryable . QueryBuilder . JoinQueryInfos = new List < JoinQueryInfo > ( ) ;
queryable . QueryBuilder . Builder = sqlBuilder ;
queryable . QueryBuilder . Context = base . Context ;
queryable . QueryBuilder . EntityType = typeof ( T ) ;
queryable . QueryBuilder . LambdaExpressions = InstanceFactory . GetLambdaExpressions ( base . CurrentConnectionConfig ) ;
//master
var shortName1 = joinExpression . Parameters [ 0 ] . Name ;
var sqlObj1 = joinQueryable1 . ToSql ( ) ;
string sql1 = sqlObj1 . Key ;
UtilMethods . RepairReplicationParameters ( ref sql1 , sqlObj1 . Value . ToArray ( ) , 0 ) ;
queryable . QueryBuilder . EntityName = sqlBuilder . GetPackTable ( sql1 , shortName1 ) ; ;
queryable . QueryBuilder . Parameters . AddRange ( sqlObj1 . Value ) ;
//join table 1
var shortName2 = joinExpression . Parameters [ 1 ] . Name ;
var sqlObj2 = joinQueryable2 . ToSql ( ) ;
string sql2 = sqlObj2 . Key ;
UtilMethods . RepairReplicationParameters ( ref sql2 , sqlObj2 . Value . ToArray ( ) , 1 ) ;
queryable . QueryBuilder . Parameters . AddRange ( sqlObj2 . Value ) ;
var exp = queryable . QueryBuilder . GetExpressionValue ( joinExpression , ResolveExpressType . WhereMultiple ) ;
queryable . QueryBuilder . JoinQueryInfos . Add ( new JoinQueryInfo ( ) { JoinIndex = 0 , JoinType = joinType , JoinWhere = exp . GetResultString ( ) , TableName = sqlBuilder . GetPackTable ( sql2 , shortName2 ) } ) ;
return queryable ;
}
2017-08-24 15:18:53 +08:00
#endregion
2017-08-28 02:31:02 +08:00
public virtual ISugarQueryable < T > UnionAll < T > ( params ISugarQueryable < T > [ ] queryables ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2017-10-28 13:33:07 +08:00
var sqlBuilder = InstanceFactory . GetSqlbuilder ( base . Context . CurrentConnectionConfig ) ;
2017-08-28 02:31:02 +08:00
Check . Exception ( queryables . IsNullOrEmpty ( ) , "UnionAll.queryables is null " ) ;
int i = 1 ;
List < KeyValuePair < string , List < SugarParameter > > > allItems = new List < KeyValuePair < string , List < SugarParameter > > > ( ) ;
2017-08-24 15:18:53 +08:00
foreach ( var item in queryables )
{
2017-08-28 02:31:02 +08:00
var sqlObj = item . ToSql ( ) ;
string sql = sqlObj . Key ;
UtilMethods . RepairReplicationParameters ( ref sql , sqlObj . Value . ToArray ( ) , i ) ;
2017-10-23 15:26:24 +08:00
if ( sqlObj . Value . HasValue ( ) )
2017-08-28 02:31:02 +08:00
allItems . Add ( new KeyValuePair < string , List < SugarParameter > > ( sql , sqlObj . Value ) ) ;
else
allItems . Add ( new KeyValuePair < string , List < SugarParameter > > ( sql , new List < SugarParameter > ( ) ) ) ;
i + + ;
2017-08-24 15:18:53 +08:00
}
2017-09-20 13:57:46 +08:00
var allSql = sqlBuilder . GetUnionAllSql ( allItems . Select ( it = > it . Key ) . ToList ( ) ) ;
2017-08-28 02:31:02 +08:00
var allParameters = allItems . SelectMany ( it = > it . Value ) . ToArray ( ) ;
2017-12-22 16:02:29 +08:00
var resulut = base . Context . Queryable < ExpandoObject > ( ) . AS ( UtilMethods . GetPackTable ( allSql , "unionTable" ) ) . With ( SqlWith . Null ) ;
2017-08-28 02:31:02 +08:00
resulut . AddParameters ( allParameters ) ;
2017-11-28 13:17:18 +08:00
return resulut . Select < T > ( sqlBuilder . SqlSelectAll ) ;
2017-08-24 15:18:53 +08:00
}
2017-08-28 02:31:02 +08:00
public virtual ISugarQueryable < T > UnionAll < T > ( List < ISugarQueryable < T > > queryables ) where T : class , new ( )
2017-08-24 15:18:53 +08:00
{
2017-08-28 02:31:02 +08:00
Check . Exception ( queryables . IsNullOrEmpty ( ) , "UnionAll.queryables is null " ) ;
2017-08-24 15:18:53 +08:00
return UnionAll ( queryables . ToArray ( ) ) ;
}
#endregion
2017-09-20 13:57:46 +08:00
#region SqlQueryable
public ISugarQueryable < T > SqlQueryable < T > ( string sql ) where T : class , new ( )
{
2017-10-28 13:33:07 +08:00
var sqlBuilder = InstanceFactory . GetSqlbuilder ( base . Context . CurrentConnectionConfig ) ;
2017-12-22 16:02:29 +08:00
return base . Context . Queryable < T > ( ) . AS ( sqlBuilder . GetPackTable ( sql , sqlBuilder . GetDefaultShortName ( ) ) ) . With ( SqlWith . Null ) . Select ( "*" ) ;
2017-09-20 13:57:46 +08:00
}
#endregion
2017-08-24 15:18:53 +08:00
#region Insertable
public virtual IInsertable < T > Insertable < T > ( T [ ] insertObjs ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
InsertableProvider < T > reval = base . CreateInsertable ( insertObjs ) ;
return reval ;
}
public virtual IInsertable < T > Insertable < T > ( List < T > insertObjs ) where T : class , new ( )
{
Check . ArgumentNullException ( insertObjs , "Insertable.insertObjs can't be null" ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Insertable ( insertObjs . ToArray ( ) ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IInsertable < T > Insertable < T > ( T insertObj ) where T : class , new ( )
{
2017-10-28 13:33:07 +08:00
return base . Context . Insertable ( new T [ ] { insertObj } ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IInsertable < T > Insertable < T > ( Dictionary < string , object > columnDictionary ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
Check . Exception ( columnDictionary = = null | | columnDictionary . Count = = 0 , "Insertable.columnDictionary can't be null" ) ;
2017-10-28 13:33:07 +08:00
var insertObject = base . Context . Utilities . DeserializeObject < T > ( base . Context . Utilities . SerializeObject ( columnDictionary ) ) ;
2017-08-24 15:18:53 +08:00
var columns = columnDictionary . Select ( it = > it . Key ) . ToList ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Insertable ( insertObject ) . InsertColumns ( it = > columns . Any ( c = > it . Equals ( c , StringComparison . CurrentCultureIgnoreCase ) ) ) ; ;
2017-08-24 15:18:53 +08:00
}
public virtual IInsertable < T > Insertable < T > ( dynamic insertDynamicObject ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
if ( insertDynamicObject is T )
{
2017-10-28 13:33:07 +08:00
return base . Context . Insertable ( ( T ) insertDynamicObject ) ;
2017-08-24 15:18:53 +08:00
}
else
{
2017-08-28 02:31:02 +08:00
var columns = ( ( object ) insertDynamicObject ) . GetType ( ) . GetProperties ( ) . Select ( it = > it . Name ) . ToList ( ) ;
2017-08-24 15:18:53 +08:00
Check . Exception ( columns . IsNullOrEmpty ( ) , "Insertable.updateDynamicObject can't be null" ) ;
2017-10-28 13:33:07 +08:00
T insertObject = base . Context . Utilities . DeserializeObject < T > ( base . Context . Utilities . SerializeObject ( insertDynamicObject ) ) ;
return base . Context . Insertable ( insertObject ) . InsertColumns ( it = > columns . Any ( c = > it . Equals ( c , StringComparison . CurrentCultureIgnoreCase ) ) ) ;
2017-08-24 15:18:53 +08:00
}
}
#endregion
#region Deleteable
public virtual IDeleteable < T > Deleteable < T > ( ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
DeleteableProvider < T > reval = base . CreateDeleteable < T > ( ) ;
return reval ;
}
public virtual IDeleteable < T > Deleteable < T > ( Expression < Func < T , bool > > expression ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . Where ( expression ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IDeleteable < T > Deleteable < T > ( dynamic primaryKeyValue ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . In ( primaryKeyValue ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IDeleteable < T > Deleteable < T > ( dynamic [ ] primaryKeyValues ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . In ( primaryKeyValues ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IDeleteable < T > Deleteable < T > ( List < dynamic > pkValue ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . In ( pkValue ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IDeleteable < T > Deleteable < T > ( T deleteObj ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . Where ( deleteObj ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IDeleteable < T > Deleteable < T > ( List < T > deleteObjs ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Deleteable < T > ( ) . Where ( deleteObjs ) ;
2017-08-24 15:18:53 +08:00
}
#endregion
#region Updateable
public virtual IUpdateable < T > Updateable < T > ( T [ ] UpdateObjs ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
UpdateableProvider < T > reval = base . CreateUpdateable ( UpdateObjs ) ;
return reval ;
}
public virtual IUpdateable < T > Updateable < T > ( List < T > UpdateObjs ) where T : class , new ( )
{
Check . ArgumentNullException ( UpdateObjs , "Updateable.UpdateObjs can't be null" ) ;
return Updateable ( UpdateObjs . ToArray ( ) ) ;
}
public virtual IUpdateable < T > Updateable < T > ( T UpdateObj ) where T : class , new ( )
{
2017-10-28 13:33:07 +08:00
return base . Context . Updateable ( new T [ ] { UpdateObj } ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IUpdateable < T > Updateable < T > ( ) where T : class , new ( )
{
2017-10-28 13:33:07 +08:00
return base . Context . Updateable ( new T [ ] { new T ( ) } ) ;
2017-08-24 15:18:53 +08:00
}
public virtual IUpdateable < T > Updateable < T > ( Dictionary < string , object > columnDictionary ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
Check . Exception ( columnDictionary = = null | | columnDictionary . Count = = 0 , "Updateable.columnDictionary can't be null" ) ;
2017-10-28 13:33:07 +08:00
var updateObject = base . Context . Utilities . DeserializeObject < T > ( base . Context . Utilities . SerializeObject ( columnDictionary ) ) ;
2017-08-24 15:18:53 +08:00
var columns = columnDictionary . Select ( it = > it . Key ) . ToList ( ) ;
2017-10-28 13:33:07 +08:00
return base . Context . Updateable ( updateObject ) . UpdateColumns ( it = > columns . Any ( c = > it . Equals ( c , StringComparison . CurrentCultureIgnoreCase ) ) ) ; ;
2017-08-24 15:18:53 +08:00
}
public virtual IUpdateable < T > Updateable < T > ( dynamic updateDynamicObject ) where T : class , new ( )
{
InitMppingInfo < T > ( ) ;
if ( updateDynamicObject is T )
{
2017-10-28 13:33:07 +08:00
return base . Context . Updateable ( ( T ) updateDynamicObject ) ;
2017-08-24 15:18:53 +08:00
}
else
{
var columns = ( ( object ) updateDynamicObject ) . GetType ( ) . GetProperties ( ) . Select ( it = > it . Name ) . ToList ( ) ;
Check . Exception ( columns . IsNullOrEmpty ( ) , "Updateable.updateDynamicObject can't be null" ) ;
2017-10-28 13:33:07 +08:00
T updateObject = base . Context . Utilities . DeserializeObject < T > ( base . Context . Utilities . SerializeObject ( updateDynamicObject ) ) ;
return base . Context . Updateable ( updateObject ) . UpdateColumns ( it = > columns . Any ( c = > it . Equals ( c , StringComparison . CurrentCultureIgnoreCase ) ) ) ; ;
2017-08-24 15:18:53 +08:00
}
}
#endregion
#region DbFirst
public virtual IDbFirst DbFirst
{
get
{
2017-10-28 13:33:07 +08:00
IDbFirst dbFirst = InstanceFactory . GetDbFirst ( base . Context . CurrentConnectionConfig ) ;
dbFirst . Context = base . Context ;
2017-08-24 15:18:53 +08:00
dbFirst . Init ( ) ;
return dbFirst ;
}
}
#endregion
#region CodeFirst
public virtual ICodeFirst CodeFirst
{
get
{
2017-10-28 13:33:07 +08:00
ICodeFirst codeFirst = InstanceFactory . GetCodeFirst ( base . Context . CurrentConnectionConfig ) ;
codeFirst . Context = base . Context ;
2017-08-24 15:18:53 +08:00
return codeFirst ;
}
}
#endregion
2017-09-20 13:57:46 +08:00
#region Db Maintenance
2017-08-24 15:18:53 +08:00
public virtual IDbMaintenance DbMaintenance
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _DbMaintenance = = null )
2017-08-24 15:18:53 +08:00
{
2017-10-28 13:33:07 +08:00
IDbMaintenance maintenance = InstanceFactory . GetDbMaintenance ( base . Context . CurrentConnectionConfig ) ;
base . Context . _DbMaintenance = maintenance ;
maintenance . Context = base . Context ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
return base . Context . _DbMaintenance ;
2017-08-24 15:18:53 +08:00
}
}
#endregion
2017-09-20 13:57:46 +08:00
#region Entity Maintenance
2017-09-11 13:42:13 +08:00
[Obsolete("Use SqlSugarClient.EntityMaintenance")]
public virtual EntityMaintenance EntityProvider
{
2017-10-28 13:33:07 +08:00
get { return base . Context . EntityMaintenance ; }
2017-11-28 13:17:18 +08:00
set { base . Context . EntityMaintenance = value ; }
2017-09-11 13:42:13 +08:00
}
public virtual EntityMaintenance EntityMaintenance
2017-08-24 15:18:53 +08:00
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _EntityProvider = = null )
2017-08-24 15:18:53 +08:00
{
2017-10-28 13:33:07 +08:00
base . Context . _EntityProvider = new EntityMaintenance ( ) ;
base . Context . _EntityProvider . Context = base . Context ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
return base . Context . _EntityProvider ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
set { base . Context . _EntityProvider = value ; }
2017-08-24 15:18:53 +08:00
}
#endregion
#region Gobal Filter
public virtual QueryFilterProvider QueryFilter
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _QueryFilterProvider = = null )
2017-08-24 15:18:53 +08:00
{
2017-10-28 13:33:07 +08:00
base . Context . _QueryFilterProvider = new QueryFilterProvider ( ) ;
base . Context . _QueryFilterProvider . Context = base . Context ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
return base . Context . _QueryFilterProvider ;
2017-08-24 15:18:53 +08:00
}
2017-10-28 13:33:07 +08:00
set { base . Context . _QueryFilterProvider = value ; }
2017-08-24 15:18:53 +08:00
}
#endregion
#region SimpleClient
public virtual SimpleClient SimpleClient
{
get
{
2017-10-28 13:33:07 +08:00
if ( base . Context . _SimpleClient = = null )
base . Context . _SimpleClient = new SimpleClient ( base . Context ) ;
return base . Context . _SimpleClient ;
2017-08-24 15:18:53 +08:00
}
}
#endregion
#region Dispose OR Close
public virtual void Close ( )
{
2017-10-28 13:33:07 +08:00
if ( base . Context . Ado ! = null )
base . Context . Ado . Close ( ) ;
2017-08-24 15:18:53 +08:00
}
public virtual void Dispose ( )
{
2017-10-28 13:33:07 +08:00
if ( base . Context . Ado ! = null )
base . Context . Ado . Dispose ( ) ;
2017-09-05 13:14:09 +08:00
}
2017-08-24 15:18:53 +08:00
#endregion
}
}