using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SqlSugar
{
///
/// ** description:Create datathis.access object
/// ** author:sunkaixuan
/// ** date:2017/1/2
/// ** email:610262374@qq.com
///
public partial class SqlSugarProvider : ISqlSugarClient
{
#region Constructor
public SqlSugarProvider(ConnectionConfig config)
{
this.Context = this;
this.CurrentConnectionConfig = config;
this.ContextID = Guid.NewGuid();
Check.ArgumentNullException(config, "config is null");
CheckDbDependency(config);
if (StaticConfig.CompleteDbFunc != null)
{
StaticConfig.CompleteDbFunc(this);
}
}
#endregion
#region ADO Methods
///
///Datathis.operation
///
public virtual IAdo Ado
{
get
{
if (this.ContextAdo == null)
{
var result = InstanceFactory.GetAdo(this.Context.CurrentConnectionConfig);
this.ContextAdo = result;
result.Context = this;
return result;
}
return this._Ado;
}
}
#endregion
#region Aop Log Methods
public virtual AopProvider Aop { get { return new AopProvider(this); } }
#endregion
#region Util Methods
[Obsolete("Use SqlSugarClient.Utilities")]
public virtual IContextMethods RewritableMethods
{
get { return this.Context.Utilities; }
set { this.Context.Utilities = value; }
}
public virtual IContextMethods Utilities
{
get
{
if (ContextRewritableMethods == null)
{
ContextRewritableMethods = new ContextMethods();
ContextRewritableMethods.Context = this;
}
return ContextRewritableMethods;
}
set { ContextRewritableMethods = value; }
}
#endregion
#region Queryable
public QueryMethodInfo QueryableByObject(Type entityType)
{
QueryMethodInfo result = new QueryMethodInfo();
var method=this.GetType().GetMyMethod("Queryable", 0);
var methodT=method.MakeGenericMethod(entityType);
var queryableObj=methodT.Invoke(this,new object[] {});
result.QueryableObj = queryableObj;
result.Context = this.Context;
result.EntityType = entityType;
return result;
}
public QueryMethodInfo QueryableByObject(Type entityType, string shortName)
{
return this.QueryableByObject(entityType).AS(this.Context.EntityMaintenance.GetTableName(entityType),shortName);
}
///
/// Get datebase time
///
///
public DateTime GetDate()
{
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
return this.Ado.GetDateTime(sqlBuilder.FullSqlDateNow);
}
public ISugarQueryable MasterQueryable()
{
var result = this.Queryable();
result.QueryBuilder.IsDisableMasterSlaveSeparation = true;
return result;
}
public ISugarQueryable SlaveQueryable()
{
var result = this.Queryable();
result.QueryBuilder.IsEnableMasterSlaveSeparation = true;
return result;
}
///
/// Lambda Query operation
///
public virtual ISugarQueryable Queryable()
{
InitMappingInfo();
var result = this.CreateQueryable();
UtilMethods.AddDiscrimator(typeof(T), result);
return result;
}
///
/// Lambda Query operation
///
public virtual ISugarQueryable Queryable(string shortName)
{
Check.Exception(shortName.HasValue() && shortName.Length > 40, ErrorMessage.GetThrowMessage("shortName参数长度不能超过40,你可能是想用这个方法 db.SqlQueryable(sql)而不是db.Queryable(shortName)", "Queryable.shortName max length 20"));
var queryable = Queryable();
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
return queryable;
}
///
/// Lambda Query operation
///
public virtual ISugarQueryable Queryable(string tableName, string shortName)
{
var queryable = Queryable();
queryable.SqlBuilder.QueryBuilder.EntityName = tableName;
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
#region 9-12
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression)
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateQueryJoin(joinExpression, types, queryable);
return queryable;
}
#endregion
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
#region 9-12
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
var queryable = InstanceFactory.GetQueryable(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new()
{
InitMappingInfo();
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(this.CurrentConnectionConfig);
this.CreateEasyQueryJoin(joinExpression, types, queryable);
queryable.Where(joinExpression);
return queryable;
}
public virtual ISugarQueryable Queryable(ISugarQueryable queryable)
{
var sqlobj = queryable.ToSql();
var QueryBuilder = queryable.QueryBuilder;
var newQueryable = this.SqlQueryable