mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update SqlSugarClient
This commit is contained in:
parent
aed17ffabc
commit
04a457bdfc
@ -34,7 +34,7 @@ namespace SqlSugar
|
||||
protected List<IDataParameter> OutputParameters { get; set; }
|
||||
public virtual string SqlParameterKeyWord { get { return "@"; } }
|
||||
public IDbTransaction Transaction { get; set; }
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
public virtual SqlSugarContext Context { get; set; }
|
||||
internal CommandType OldCommandType { get; set; }
|
||||
internal bool OldClearParameters { get; set; }
|
||||
public IDataParameterCollection DataReaderParameters { get; set; }
|
||||
|
@ -8,12 +8,12 @@ namespace SqlSugar
|
||||
public class AopProvider
|
||||
{
|
||||
private AopProvider() { }
|
||||
public AopProvider(SqlSugarClient context)
|
||||
public AopProvider(SqlSugarContext context)
|
||||
{
|
||||
this.Context = context;
|
||||
this.Context.Ado.IsEnableLogEvent = true;
|
||||
}
|
||||
private SqlSugarClient Context { get; set; }
|
||||
private SqlSugarContext Context { get; set; }
|
||||
public Action<DiffLogModel> OnDiffLogEvent { set { this.Context.Ado.DiffLogEvent = value; } }
|
||||
public Action<SqlSugarException> OnError { set { this.Context.Ado.ErrorEvent = value; } }
|
||||
public Action<string, SugarParameter[]> OnLogExecuting { set { this.Context.Ado.LogEventStarting = value; } }
|
||||
|
@ -8,7 +8,7 @@ namespace SqlSugar
|
||||
public partial class CodeFirstProvider : ICodeFirst
|
||||
{
|
||||
#region Properties
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
public virtual SqlSugarContext Context { get; set; }
|
||||
protected bool IsBackupTable { get; set; }
|
||||
protected int MaxBackupDataRows { get; set; }
|
||||
protected virtual int DefultLength { get; set; }
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class DbBindAccessory
|
||||
{
|
||||
protected List<T> GetEntityList<T>(SqlSugarClient context, IDataReader dataReader)
|
||||
protected List<T> GetEntityList<T>(SqlSugarContext context, IDataReader dataReader)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
var fieldNames = GetDataReaderNames(dataReader);
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
public abstract partial class DbBindProvider : DbBindAccessory, IDbBind
|
||||
{
|
||||
#region Properties
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
public virtual SqlSugarContext Context { get; set; }
|
||||
public abstract List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
|
||||
#endregion
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private SqlSugarClient Context = null;
|
||||
private SqlSugarContext Context = null;
|
||||
private IDataReaderEntityBuilder<T> DynamicBuilder;
|
||||
private IDataRecord DataRecord;
|
||||
private static readonly MethodInfo isDBNullMethod = typeof(IDataRecord).GetMethod("IsDBNull", new Type[] { typeof(int) });
|
||||
@ -65,7 +65,7 @@ namespace SqlSugar
|
||||
private static readonly MethodInfo getOther = typeof(IDataRecordExtensions).GetMethod("GetOther");
|
||||
private static readonly MethodInfo getSqliteTypeNull = typeof(IDataRecordExtensions).GetMethod("GetSqliteTypeNull");
|
||||
private static readonly MethodInfo getSqliteType = typeof(IDataRecordExtensions).GetMethod("GetSqliteType");
|
||||
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarClient) });
|
||||
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarContext) });
|
||||
|
||||
private delegate T Load(IDataRecord dataRecord);
|
||||
private Load handler;
|
||||
@ -77,7 +77,7 @@ namespace SqlSugar
|
||||
|
||||
}
|
||||
|
||||
public IDataReaderEntityBuilder(SqlSugarClient context, IDataRecord dataRecord,List<string> fieldNames)
|
||||
public IDataReaderEntityBuilder(SqlSugarContext context, IDataRecord dataRecord,List<string> fieldNames)
|
||||
{
|
||||
this.Context = context;
|
||||
this.DataRecord = dataRecord;
|
||||
|
@ -243,7 +243,7 @@ namespace SqlSugar
|
||||
return t;
|
||||
}
|
||||
|
||||
public static object GetEntity(this IDataReader dr, SqlSugarClient context)
|
||||
public static object GetEntity(this IDataReader dr, SqlSugarContext context)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DbFirstProvider : IDbFirst
|
||||
{
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
public virtual SqlSugarContext Context { get; set; }
|
||||
private string ClassTemplate { get; set; }
|
||||
private string ClassDescriptionTemplate { get; set; }
|
||||
private string PropertyTemplate { get; set; }
|
||||
|
@ -9,7 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
#region Context
|
||||
private ISqlBuilder _SqlBuilder;
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ISqlBuilder SqlBuilder
|
||||
{
|
||||
get
|
||||
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class DeleteableProvider<T> : IDeleteable<T> where T : class, new()
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public DeleteBuilder DeleteBuilder { get; set; }
|
||||
|
@ -9,7 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class EntityMaintenance
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
|
||||
public EntityInfo GetEntityInfo<T>()
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class QueryFilterProvider : IFilter
|
||||
{
|
||||
internal SqlSugarClient Context { get; set; }
|
||||
internal SqlSugarContext Context { get; set; }
|
||||
private List<SqlFilterItem> _Filters { get; set; }
|
||||
|
||||
public IFilter Add(SqlFilterItem filter)
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class InsertableProvider<T> : IInsertable<T> where T : class, new()
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public IAdo Ado { get { return Context.Ado; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public InsertBuilder InsertBuilder { get; set; }
|
||||
|
@ -16,7 +16,7 @@ namespace SqlSugar
|
||||
#region T1
|
||||
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public IDbBind Bind { get { return this.Db.DbBind; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
@ -1597,7 +1597,7 @@ namespace SqlSugar
|
||||
foreach (var item in result)
|
||||
{
|
||||
var contextProperty = item.GetType().GetProperty("Context");
|
||||
SqlSugarClient newClient = this.Context.Utilities.CopyContext();
|
||||
SqlSugarContext newClient = this.Context.Utilities.CopyContext();
|
||||
contextProperty.SetValue(item, newClient, null);
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,19 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class SaveableProvider<T> : ISaveable<T> where T : class, new()
|
||||
{
|
||||
internal SaveableProvider(SqlSugarClient context,List<T> saveObjects)
|
||||
internal SaveableProvider(SqlSugarContext context,List<T> saveObjects)
|
||||
{
|
||||
this.saveObjects = saveObjects;
|
||||
this.Context = context;
|
||||
this.Context.InitMppingInfo<T>();
|
||||
}
|
||||
internal SaveableProvider(SqlSugarClient context, T saveObject)
|
||||
internal SaveableProvider(SqlSugarContext context, T saveObject)
|
||||
{
|
||||
this.saveObjects = new List<T>() { saveObject };
|
||||
this.Context = context;
|
||||
this.Context.InitMppingInfo<T>();
|
||||
}
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public List<T> saveObjects = new List<T>();
|
||||
public List<T> existsObjects = null;
|
||||
public List<T> insertObjects
|
||||
|
@ -13,7 +13,7 @@ namespace SqlSugar
|
||||
|
||||
#region Common Properties
|
||||
public EntityInfo EntityInfo { get; set; }
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ILambdaExpressions LambdaExpressions { get; set; }
|
||||
public List<SugarParameter> Parameters { get; set; }
|
||||
public StringBuilder sql { get; set; }
|
||||
|
@ -18,7 +18,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Common Properties
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ILambdaExpressions LambdaExpressions { get; set; }
|
||||
public ISqlBuilder Builder { get; set; }
|
||||
public StringBuilder sql { get; set; }
|
||||
|
@ -27,7 +27,7 @@ namespace SqlSugar
|
||||
|
||||
#region Service object
|
||||
public StringBuilder sql { get; set; }
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ILambdaExpressions LambdaExpressions { get; set; }
|
||||
public ISqlBuilder Builder { get; set; }
|
||||
#endregion
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
public abstract partial class SqlBuilderProvider : SqlBuilderAccessory, ISqlBuilder
|
||||
{
|
||||
#region Properties
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public CommandType CommandType { get; set; }
|
||||
public DeleteBuilder DeleteBuilder { get; set; }
|
||||
public InsertBuilder InsertBuilder { get; set; }
|
||||
|
@ -17,7 +17,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public string Fields
|
||||
{
|
||||
get
|
||||
|
@ -17,7 +17,7 @@ namespace SqlSugar
|
||||
this.WhereValues = new List<string>();
|
||||
this.Parameters = new List<SugarParameter>();
|
||||
}
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ILambdaExpressions LambdaExpressions { get; set; }
|
||||
public ISqlBuilder Builder { get; set; }
|
||||
public StringBuilder sql { get; set; }
|
||||
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
public class UpdateableProvider<T> : IUpdateable<T> where T : class, new()
|
||||
{
|
||||
#region Property
|
||||
public SqlSugarClient Context { get; internal set; }
|
||||
public SqlSugarContext Context { get; internal set; }
|
||||
public EntityInfo EntityInfo { get; internal set; }
|
||||
public ISqlBuilder SqlBuilder { get; internal set; }
|
||||
public UpdateBuilder UpdateBuilder { get; set; }
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheKeyBuider
|
||||
{
|
||||
public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
|
||||
public static CacheKey GetKey(SqlSugarContext context, QueryBuilder queryBuilder)
|
||||
{
|
||||
CacheKey result = new CacheKey();
|
||||
result.Database = context.Context.Ado.Connection.Database;
|
||||
@ -38,7 +38,7 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddTables(SqlSugarClient context, QueryBuilder queryBuilder, CacheKey result)
|
||||
private static void AddTables(SqlSugarContext context, QueryBuilder queryBuilder, CacheKey result)
|
||||
{
|
||||
result.Tables = new List<string>();
|
||||
result.Tables.Add(context.EntityMaintenance.GetTableName(queryBuilder.EntityName));
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheSchemeMain
|
||||
{
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarClient context)
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarContext context)
|
||||
{
|
||||
CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);
|
||||
string keyString = key.ToString();
|
||||
|
@ -9,11 +9,11 @@ namespace SqlSugar
|
||||
{
|
||||
private Dictionary<string, object> caches = new Dictionary<string, object>();
|
||||
private List<T> _list { get; set; }
|
||||
private SqlSugarClient _context { get; set; }
|
||||
private SqlSugarContext _context { get; set; }
|
||||
private MapperCache()
|
||||
{
|
||||
}
|
||||
public MapperCache(List<T> list, SqlSugarClient context)
|
||||
public MapperCache(List<T> list, SqlSugarContext context)
|
||||
{
|
||||
_list = list;
|
||||
_context = context;
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
{
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[JsonIgnore]
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public ISugarQueryable<T> CreateMapping<T>() where T : class, new()
|
||||
{
|
||||
Check.ArgumentNullException(Context, "Please use Sqlugar.ModelContext");
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
/// Equal to NULL representing global
|
||||
/// </summary>
|
||||
public string FilterName { get; set; }
|
||||
public Func<SqlSugarClient,SqlFilterResult> FilterValue { get; set; }
|
||||
public Func<SqlSugarContext,SqlFilterResult> FilterValue { get; set; }
|
||||
/// <summary>
|
||||
/// Is it a multiple table query?
|
||||
/// </summary>
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class ContextMethods : IContextMethods
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
#region DataReader
|
||||
|
||||
/// <summary>
|
||||
@ -268,9 +268,9 @@ namespace SqlSugar
|
||||
return DeserializeObject<T>(jsonString);
|
||||
}
|
||||
}
|
||||
public SqlSugarClient CopyContext(bool isCopyEvents = false)
|
||||
public SqlSugarContext CopyContext(bool isCopyEvents = false)
|
||||
{
|
||||
var newClient = new SqlSugarClient(this.TranslateCopy(Context.CurrentConnectionConfig));
|
||||
var newClient = new SqlSugarContext(this.TranslateCopy(Context.CurrentConnectionConfig));
|
||||
newClient.CurrentConnectionConfig.ConfigureExternalServices = Context.CurrentConnectionConfig.ConfigureExternalServices;
|
||||
newClient.MappingColumns = this.TranslateCopy(Context.MappingColumns);
|
||||
newClient.MappingTables = this.TranslateCopy(Context.MappingTables);
|
||||
|
@ -8,8 +8,8 @@ namespace SqlSugar
|
||||
{
|
||||
public class SugarMapper
|
||||
{
|
||||
private SqlSugarClient _context;
|
||||
public SugarMapper(SqlSugarClient context)
|
||||
private SqlSugarContext _context;
|
||||
public SugarMapper(SqlSugarContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class SqlSugarClient
|
||||
public partial class SqlSugarContext
|
||||
{
|
||||
#region Properties
|
||||
public SqlSugarClient Context
|
||||
public SqlSugarContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty())
|
||||
{
|
||||
CallContext.ContextList.Value = new List<SqlSugarClient>();
|
||||
CallContext.ContextList.Value = new List<SqlSugarContext>();
|
||||
CallContext.ContextList.Value.Add(_Context);
|
||||
}
|
||||
else
|
||||
@ -55,7 +55,7 @@ namespace SqlSugar
|
||||
|
||||
#region Fields
|
||||
protected ISqlBuilder _SqlBuilder;
|
||||
protected SqlSugarClient _Context { get; set; }
|
||||
protected SqlSugarContext _Context { get; set; }
|
||||
protected EntityMaintenance _EntityProvider;
|
||||
protected IAdo _Ado;
|
||||
protected ILambdaExpressions _LambdaExpressions;
|
||||
|
@ -16,7 +16,7 @@ namespace SqlSugar
|
||||
IDbTransaction Transaction { get; set; }
|
||||
IDataParameter[] ToIDbDataParameter(params SugarParameter[] pars);
|
||||
SugarParameter[] GetParameters(object obj, PropertyInfo[] propertyInfo = null);
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
void ExecuteBefore(string sql, SugarParameter[] pars);
|
||||
void ExecuteAfter(string sql, SugarParameter[] pars);
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface ICodeFirst
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
ICodeFirst BackupTable(int maxBackupDataRows = int.MaxValue);
|
||||
ICodeFirst SetStringDefaultLength(int length);
|
||||
void InitTables(string entitiesNamespace);
|
||||
|
@ -10,14 +10,14 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface IContextMethods
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
||||
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
|
||||
List<T> DataReaderToList<T>(IDataReader reader);
|
||||
string SerializeObject(object value);
|
||||
T DeserializeObject<T>(string value);
|
||||
T TranslateCopy<T>(T sourceObject);
|
||||
SqlSugarClient CopyContext(bool isCopyEvents = false);
|
||||
SqlSugarContext CopyContext(bool isCopyEvents = false);
|
||||
dynamic DataTableToDynamic(DataTable table);
|
||||
List<T> DataTableToList<T>(DataTable table);
|
||||
ICacheService GetReflectionInoCacheInstance();
|
||||
|
@ -9,7 +9,7 @@ namespace SqlSugar
|
||||
{
|
||||
string SqlTemplate { get; }
|
||||
List<SugarParameter> Parameters { get; set; }
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
StringBuilder sql { get; set; }
|
||||
string ToSqlString();
|
||||
void Clear();
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface IDbBind
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
List<string> GuidThrow { get; }
|
||||
List<string> IntThrow { get; }
|
||||
List<string> StringThrow { get; }
|
||||
|
@ -6,7 +6,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface IDbFirst
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
IDbFirst SettingClassTemplate(Func<string, string> func);
|
||||
IDbFirst SettingClassDescriptionTemplate(Func<string, string> func);
|
||||
IDbFirst SettingPropertyTemplate(Func<string, string> func);
|
||||
|
@ -6,7 +6,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface IDbMaintenance
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
|
||||
#region DML
|
||||
List<DbTableInfo> GetViewInfoList(bool isCache=true);
|
||||
|
@ -15,7 +15,7 @@ namespace SqlSugar
|
||||
|
||||
List<JoinQueryInfo> JoinQueryInfos { get; set; }
|
||||
bool IsSingle { get; set; }
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
IDbMethods DbMehtods { get; set; }
|
||||
Expression Expression { get; set; }
|
||||
int Index { get; set; }
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface ISugarQueryable<T>
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
ISqlBuilder SqlBuilder { get; set; }
|
||||
QueryBuilder QueryBuilder { get; set; }
|
||||
ISugarQueryable<T> Clone();
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface ISqlBuilder
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
SqlSugarContext Context { get; set; }
|
||||
CommandType CommandType { get; set; }
|
||||
String AppendWhereOrAnd(bool isWhere, string sqlString);
|
||||
string AppendHaving(string sqlString);
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
IAdo Ado { get; }
|
||||
AopProvider Aop { get; }
|
||||
ICodeFirst CodeFirst { get; }
|
||||
SqlSugarClient Context { get; set; }
|
||||
ISqlSugarClient Context { get; set; }
|
||||
Guid ContextID { get; set; }
|
||||
ConnectionConfig CurrentConnectionConfig { get; set; }
|
||||
IDbFirst DbFirst { get; }
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
}
|
||||
internal class PostgreSQLExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context
|
||||
public SqlSugarContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public MySqlExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new MySqlMethod();
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class OracleExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public OracleExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new OracleMethod();
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class SqlServerExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public SqlServerExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new SqlServerMethod();
|
||||
|
@ -4,7 +4,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class SqliteExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public SqlSugarContext Context { get; set; }
|
||||
public SqliteExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new SqliteMethod();
|
||||
|
@ -8,14 +8,14 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class SimpleClient
|
||||
{
|
||||
protected SqlSugarClient Context { get; set; }
|
||||
public SqlSugarClient FullClient { get { return this.Context; } }
|
||||
protected SqlSugarContext Context { get; set; }
|
||||
public SqlSugarContext FullClient { get { return this.Context; } }
|
||||
|
||||
private SimpleClient()
|
||||
{
|
||||
|
||||
}
|
||||
public SimpleClient(SqlSugarClient context)
|
||||
public SimpleClient(SqlSugarContext context)
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
@ -123,14 +123,14 @@ namespace SqlSugar
|
||||
}
|
||||
public partial class SimpleClient<T> where T : class, new()
|
||||
{
|
||||
protected SqlSugarClient Context { get; set; }
|
||||
public SqlSugarClient FullClient { get { return this.Context; } }
|
||||
protected SqlSugarContext Context { get; set; }
|
||||
public SqlSugarContext FullClient { get { return this.Context; } }
|
||||
|
||||
private SimpleClient()
|
||||
{
|
||||
|
||||
}
|
||||
public SimpleClient(SqlSugarClient context)
|
||||
public SimpleClient(SqlSugarContext context)
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
|
@ -128,6 +128,7 @@
|
||||
<Compile Include="Realization\Oracle\Insertable\OracleInsertable.cs" />
|
||||
<Compile Include="Realization\Oracle\Updateable\OracleUpdateable.cs" />
|
||||
<Compile Include="IntegrationServices\SerializeService.cs" />
|
||||
<Compile Include="SqlSugarClient.cs" />
|
||||
<Compile Include="Utilities\CallContext.cs" />
|
||||
<Compile Include="Utilities\ReflectionExtensions.cs" />
|
||||
<Compile Include="Realization\MySql\CodeFirst\MySqlCodeFirst.cs" />
|
||||
@ -275,7 +276,7 @@
|
||||
<Compile Include="Interface\IUpdateable.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Infrastructure\SqlSugarAccessory.cs" />
|
||||
<Compile Include="SqlSugarClient.cs" />
|
||||
<Compile Include="SqlSugarContext.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="References\MySql.Data.dll" />
|
||||
|
File diff suppressed because it is too large
Load Diff
969
Src/Asp.Net/SqlSugar/SqlSugarContext.cs
Normal file
969
Src/Asp.Net/SqlSugar/SqlSugarContext.cs
Normal file
@ -0,0 +1,969 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
///<summary>
|
||||
/// ** description:Create datathis.access object
|
||||
/// ** author:sunkaixuan
|
||||
/// ** date:2017/1/2
|
||||
/// ** email:610262374@qq.com
|
||||
/// </summary>
|
||||
public partial class SqlSugarContext : IDisposable, ISqlSugarClient
|
||||
{
|
||||
|
||||
#region Constructor
|
||||
public SqlSugarContext(ConnectionConfig config)
|
||||
{
|
||||
this.Context = this;
|
||||
this.CurrentConnectionConfig = config;
|
||||
this.ContextID = Guid.NewGuid();
|
||||
Check.ArgumentNullException(config, "config is null");
|
||||
switch (config.DbType)
|
||||
{
|
||||
case DbType.MySql:
|
||||
DependencyManagement.TryMySqlData();
|
||||
break;
|
||||
case DbType.SqlServer:
|
||||
break;
|
||||
case DbType.Sqlite:
|
||||
DependencyManagement.TrySqlite();
|
||||
break;
|
||||
case DbType.Oracle:
|
||||
DependencyManagement.TryOracle();
|
||||
break;
|
||||
case DbType.PostgreSQL:
|
||||
DependencyManagement.TryPostgreSQL();
|
||||
break;
|
||||
default:
|
||||
throw new Exception("ConnectionConfig.DbType is null");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ADO Methods
|
||||
/// <summary>
|
||||
///Datathis.operation
|
||||
/// </summary>
|
||||
public virtual IAdo Ado
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.ContextAdo == null)
|
||||
{
|
||||
var result = InstanceFactory.GetAdo(this.Context.CurrentConnectionConfig);
|
||||
this.ContextAdo = result;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
return this.Context._Ado;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aop Log Methods
|
||||
public virtual AopProvider Aop { get { return new AopProvider(this.Context); } }
|
||||
#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.Context;
|
||||
}
|
||||
return ContextRewritableMethods;
|
||||
}
|
||||
set { ContextRewritableMethods = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Queryable
|
||||
/// <summary>
|
||||
/// Get datebase time
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DateTime GetDate()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
return this.Ado.GetDateTime(sqlBuilder.FullSqlDateNow);
|
||||
}
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>()
|
||||
{
|
||||
|
||||
InitMppingInfo<T>();
|
||||
var result = this.CreateQueryable<T>();
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>(string shortName)
|
||||
{
|
||||
Check.Exception(shortName.HasValue() && shortName.Length > 20, ErrorMessage.GetThrowMessage("shortName参数长度不能超过20,你可能是想用这个方法 db.SqlQueryable(sql)而不是db.Queryable(shortName)", "Queryable.shortName max length 20"));
|
||||
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)
|
||||
{
|
||||
InitMppingInfo<T, T2>();
|
||||
var types = new Type[] { typeof(T2) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2>(this.CurrentConnectionConfig);
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2>();
|
||||
var types = new Type[] { typeof(T2) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2>(this.CurrentConnectionConfig);
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3>(this.CurrentConnectionConfig);
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3,JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4>(this.CurrentConnectionConfig);
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4,JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2, T3, T4>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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,JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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,JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.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)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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, JoinQueryInfos>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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>(this.CurrentConnectionConfig);
|
||||
this.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>(this.CurrentConnectionConfig);
|
||||
this.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>(this.CurrentConnectionConfig);
|
||||
this.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>(this.CurrentConnectionConfig);
|
||||
this.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>(this.CurrentConnectionConfig);
|
||||
this.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, T7>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.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, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.CreateEasyQueryJoin(joinExpression, types, queryable);
|
||||
queryable.Where(joinExpression);
|
||||
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, bool>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.CreateEasyQueryJoin(joinExpression, types, queryable);
|
||||
queryable.Where(joinExpression);
|
||||
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, bool>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.CreateEasyQueryJoin(joinExpression, types, queryable);
|
||||
queryable.Where(joinExpression);
|
||||
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, bool>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, 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>(this.CurrentConnectionConfig);
|
||||
this.CreateEasyQueryJoin(joinExpression, types, queryable);
|
||||
queryable.Where(joinExpression);
|
||||
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, bool>> joinExpression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
|
||||
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>(this.CurrentConnectionConfig);
|
||||
this.CreateEasyQueryJoin(joinExpression, types, queryable);
|
||||
queryable.Where(joinExpression);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Queryable<T>(ISugarQueryable<T> queryable) where T : class, new()
|
||||
{
|
||||
var sqlobj = queryable.ToSql();
|
||||
return this.SqlQueryable<T>(sqlobj.Key).AddParameters(sqlobj.Value);
|
||||
}
|
||||
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(this.Context.CurrentConnectionConfig);
|
||||
|
||||
sqlBuilder.Context = this.Context;
|
||||
InitMppingInfo<T, T2>();
|
||||
var types = new Type[] { typeof(T2) };
|
||||
var queryable = InstanceFactory.GetQueryable<T, T2>(this.CurrentConnectionConfig);
|
||||
queryable.Context = this.Context;
|
||||
queryable.SqlBuilder = sqlBuilder;
|
||||
queryable.QueryBuilder = InstanceFactory.GetQueryBuilder(this.CurrentConnectionConfig);
|
||||
queryable.QueryBuilder.JoinQueryInfos = new List<JoinQueryInfo>();
|
||||
queryable.QueryBuilder.Builder = sqlBuilder;
|
||||
queryable.QueryBuilder.Context = this.Context;
|
||||
queryable.QueryBuilder.EntityType = typeof(T);
|
||||
queryable.QueryBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.CurrentConnectionConfig);
|
||||
|
||||
//master
|
||||
var shortName1 = joinExpression.Parameters[0].Name;
|
||||
var sqlObj1 = joinQueryable1.ToSql();
|
||||
string sql1 = sqlObj1.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql1, sqlObj1.Value.ToArray(), 0, "Join");
|
||||
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, "Join");
|
||||
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;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public virtual ISugarQueryable<T> UnionAll<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
|
||||
int i = 1;
|
||||
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
|
||||
foreach (var item in queryables)
|
||||
{
|
||||
var sqlObj = item.ToSql();
|
||||
string sql = sqlObj.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i, "UnionAll");
|
||||
if (sqlObj.Value.HasValue())
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
|
||||
else
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, new List<SugarParameter>()));
|
||||
i++;
|
||||
}
|
||||
var allSql = sqlBuilder.GetUnionAllSql(allItems.Select(it => it.Key).ToList());
|
||||
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
|
||||
var resulut = this.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable")).With(SqlWith.Null);
|
||||
resulut.AddParameters(allParameters);
|
||||
return resulut.Select<T>(sqlBuilder.SqlSelectAll);
|
||||
}
|
||||
public virtual ISugarQueryable<T> UnionAll<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
|
||||
{
|
||||
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
|
||||
return UnionAll(queryables.ToArray());
|
||||
}
|
||||
public virtual ISugarQueryable<T> Union<T>(params ISugarQueryable<T>[] queryables) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null ");
|
||||
int i = 1;
|
||||
List<KeyValuePair<string, List<SugarParameter>>> allItems = new List<KeyValuePair<string, List<SugarParameter>>>();
|
||||
foreach (var item in queryables)
|
||||
{
|
||||
var sqlObj = item.ToSql();
|
||||
string sql = sqlObj.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i, "Union");
|
||||
if (sqlObj.Value.HasValue())
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
|
||||
else
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, new List<SugarParameter>()));
|
||||
i++;
|
||||
}
|
||||
var allSql = sqlBuilder.GetUnionSql(allItems.Select(it => it.Key).ToList());
|
||||
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
|
||||
var resulut = this.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable")).With(SqlWith.Null);
|
||||
resulut.AddParameters(allParameters);
|
||||
return resulut.Select<T>(sqlBuilder.SqlSelectAll);
|
||||
}
|
||||
public virtual ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
|
||||
{
|
||||
Check.Exception(queryables.IsNullOrEmpty(), "Union.queryables is null ");
|
||||
return Union(queryables.ToArray());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SqlQueryable
|
||||
public ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
|
||||
return this.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select(sqlBuilder.GetDefaultShortName() + ".*");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Insertable
|
||||
public virtual IInsertable<T> Insertable<T>(T[] insertObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
InsertableProvider<T> result = this.CreateInsertable(insertObjs);
|
||||
return result;
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(List<T> insertObjs) where T : class, new()
|
||||
{
|
||||
if (insertObjs == null|| insertObjs.IsNullOrEmpty())
|
||||
{
|
||||
insertObjs = new List<T>();
|
||||
insertObjs.Add(default(T));
|
||||
}
|
||||
return this.Context.Insertable(insertObjs.ToArray());
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(T insertObj) where T : class, new()
|
||||
{
|
||||
return this.Context.Insertable(new T[] { insertObj });
|
||||
}
|
||||
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");
|
||||
var insertObject = this.Context.Utilities.DeserializeObject<T>(this.Context.Utilities.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
return this.Context.Insertable(insertObject).InsertColumns(columns.ToArray()); ;
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (insertDynamicObject is T)
|
||||
{
|
||||
return this.Context.Insertable((T)insertDynamicObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var columns = ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
|
||||
Check.Exception(columns.IsNullOrEmpty(), "Insertable.updateDynamicObject can't be null");
|
||||
T insertObject = this.Context.Utilities.DeserializeObject<T>(this.Context.Utilities.SerializeObject(insertDynamicObject));
|
||||
return this.Context.Insertable(insertObject).InsertColumns(columns.ToArray());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Deleteable
|
||||
public virtual IDeleteable<T> Deleteable<T>() where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
DeleteableProvider<T> result = this.CreateDeleteable<T>();
|
||||
return result;
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().Where(expression);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().In(primaryKeyValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().In(primaryKeyValues);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().In(pkValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().Where(deleteObj);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Context.Deleteable<T>().Where(deleteObjs);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Updateable
|
||||
public virtual IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
UpdateableProvider<T> result = this.CreateUpdateable(UpdateObjs);
|
||||
return result;
|
||||
}
|
||||
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()
|
||||
{
|
||||
return this.Context.Updateable(new T[] { UpdateObj });
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>() where T : class, new()
|
||||
{
|
||||
var result = this.Context.Updateable(new T[] { new T() });
|
||||
result.UpdateParameterIsNull = true;
|
||||
return result;
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(Expression<Func<T, T>> columns) where T : class, new()
|
||||
{
|
||||
var result = this.Context.Updateable<T>().SetColumns(columns);
|
||||
result.UpdateParameterIsNull = true;
|
||||
return result;
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(Expression<Func<T, bool>> columns) where T : class, new()
|
||||
{
|
||||
var result = this.Context.Updateable<T>().SetColumns(columns);
|
||||
result.UpdateParameterIsNull = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
var updateObject = this.Context.Utilities.DeserializeObject<T>(this.Context.Utilities.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
return this.Context.Updateable(updateObject).UpdateColumns(columns.ToArray()); ;
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (updateDynamicObject is T)
|
||||
{
|
||||
return this.Context.Updateable((T)updateDynamicObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var columns = ((object)updateDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
|
||||
Check.Exception(columns.IsNullOrEmpty(), "Updateable.updateDynamicObject can't be null");
|
||||
T updateObject = this.Context.Utilities.DeserializeObject<T>(this.Context.Utilities.SerializeObject(updateDynamicObject));
|
||||
return this.Context.Updateable(updateObject).UpdateColumns(columns.ToArray()); ;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Saveable
|
||||
public ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new()
|
||||
{
|
||||
return new SaveableProvider<T>(this, saveObjects);
|
||||
}
|
||||
public ISaveable<T> Saveable<T>(T saveObject) where T : class, new()
|
||||
{
|
||||
return new SaveableProvider<T>(this, saveObject);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DbFirst
|
||||
public virtual IDbFirst DbFirst
|
||||
{
|
||||
get
|
||||
{
|
||||
IDbFirst dbFirst = InstanceFactory.GetDbFirst(this.Context.CurrentConnectionConfig);
|
||||
dbFirst.Context = this.Context;
|
||||
dbFirst.Init();
|
||||
return dbFirst;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CodeFirst
|
||||
public virtual ICodeFirst CodeFirst
|
||||
{
|
||||
get
|
||||
{
|
||||
ICodeFirst codeFirst = InstanceFactory.GetCodeFirst(this.Context.CurrentConnectionConfig);
|
||||
codeFirst.Context = this.Context;
|
||||
return codeFirst;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Db Maintenance
|
||||
public virtual IDbMaintenance DbMaintenance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Context._DbMaintenance == null)
|
||||
{
|
||||
IDbMaintenance maintenance = InstanceFactory.GetDbMaintenance(this.Context.CurrentConnectionConfig);
|
||||
this.Context._DbMaintenance = maintenance;
|
||||
maintenance.Context = this.Context;
|
||||
}
|
||||
return this.Context._DbMaintenance;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Entity Maintenance
|
||||
[Obsolete("Use SqlSugarClient.EntityMaintenance")]
|
||||
public virtual EntityMaintenance EntityProvider
|
||||
{
|
||||
get { return this.Context.EntityMaintenance; }
|
||||
set { this.Context.EntityMaintenance = value; }
|
||||
}
|
||||
public virtual EntityMaintenance EntityMaintenance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Context._EntityProvider == null)
|
||||
{
|
||||
this.Context._EntityProvider = new EntityMaintenance();
|
||||
this.Context._EntityProvider.Context = this.Context;
|
||||
}
|
||||
return this.Context._EntityProvider;
|
||||
}
|
||||
set { this.Context._EntityProvider = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Gobal Filter
|
||||
public virtual QueryFilterProvider QueryFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Context._QueryFilterProvider == null)
|
||||
{
|
||||
this.Context._QueryFilterProvider = new QueryFilterProvider();
|
||||
this.Context._QueryFilterProvider.Context = this.Context;
|
||||
}
|
||||
return this.Context._QueryFilterProvider;
|
||||
}
|
||||
set { this.Context._QueryFilterProvider = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SimpleClient
|
||||
[Obsolete("Use SqlSugarClient.GetSimpleClient() Or SqlSugarClient.GetSimpleClient<T>() ")]
|
||||
public virtual SimpleClient SimpleClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Context._SimpleClient == null)
|
||||
this.Context._SimpleClient = new SimpleClient(this.Context);
|
||||
return this.Context._SimpleClient;
|
||||
}
|
||||
}
|
||||
public virtual SimpleClient<T> GetSimpleClient<T>() where T : class, new()
|
||||
{
|
||||
return new SimpleClient<T>(this.Context);
|
||||
}
|
||||
public virtual SimpleClient GetSimpleClient()
|
||||
{
|
||||
if (this.Context._SimpleClient == null)
|
||||
this.Context._SimpleClient = new SimpleClient(this.Context);
|
||||
return this.Context._SimpleClient;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose OR Close
|
||||
public virtual void Close()
|
||||
{
|
||||
if (this.Context.Ado != null)
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
public virtual void Open()
|
||||
{
|
||||
if (this.Context.Ado != null)
|
||||
this.Context.Ado.Open();
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (this.Context.Ado != null)
|
||||
this.Context.Ado.Dispose();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Queue
|
||||
public int SaveQueues(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.ExecuteCommand(sql, parameters); });
|
||||
}
|
||||
|
||||
public Task<int> SaveQueuesAsync(bool isTran = true)
|
||||
{
|
||||
var result = new Task<int>(() => { return SaveQueues(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public List<T> SaveQueues<T>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T>(sql, parameters); });
|
||||
}
|
||||
public Task<List<T>> SaveQueuesAsync<T>(bool isTran = true)
|
||||
{
|
||||
var result = new Task<List<T>>(() => { return SaveQueues<T>(); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public Tuple<List<T>, List<T2>> SaveQueues<T, T2>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>>> SaveQueuesAsync<T, T2>(bool isTran = true)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>>>(() => { return SaveQueues<T, T2>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>> SaveQueues<T, T2, T3>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>>> SaveQueuesAsync<T, T2, T3>(bool isTran = true)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>, List<T3>>>(() => { return SaveQueues<T, T2, T3>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>> SaveQueues<T, T2, T3, T4>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SaveQueuesAsync<T, T2, T3, T4>(bool isTran = true)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>>(() => { return SaveQueues<T, T2, T3, T4>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SaveQueues<T, T2, T3, T4, T5>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SaveQueuesAsync<T, T2, T3, T4, T5>(bool isTran = true)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>>(() => { return SaveQueues<T, T2, T3, T4, T5>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SaveQueues<T, T2, T3, T4, T5, T6>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5, T6>(sql, parameters); });
|
||||
}
|
||||
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)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>>(() => { return SaveQueues<T, T2, T3, T4, T5, T6>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
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)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5, T6, T7>(sql, parameters); });
|
||||
}
|
||||
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)
|
||||
{
|
||||
var result = new Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>>(() => { return SaveQueues<T, T2, T3, T4, T5, T6, T7>(isTran); });
|
||||
result.Start();
|
||||
return result;
|
||||
}
|
||||
public void AddQueue(string sql, object parsmeters=null)
|
||||
{
|
||||
if (Queues == null)
|
||||
{
|
||||
Queues = new QueueList();
|
||||
}
|
||||
this.Queues.Add(sql,this.Context.Ado.GetParameters(parsmeters));
|
||||
}
|
||||
public void AddQueue(string sql, SugarParameter parsmeter)
|
||||
{
|
||||
if (Queues == null)
|
||||
{
|
||||
Queues = new QueueList();
|
||||
}
|
||||
this.Queues.Add(sql, new List<SugarParameter>() { parsmeter });
|
||||
}
|
||||
public void AddQueue(string sql, List<SugarParameter> parsmeters)
|
||||
{
|
||||
if (Queues == null)
|
||||
{
|
||||
Queues = new QueueList();
|
||||
}
|
||||
this.Queues.Add(sql, parsmeters);
|
||||
}
|
||||
public QueueList Queues = new QueueList();
|
||||
|
||||
private T SaveQueuesProvider<T>(bool isTran, Func<string, List<SugarParameter>, T> func)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.CurrentConnectionConfig.DbType == DbType.Oracle) {
|
||||
throw new Exception("Oracle no support SaveQueues");
|
||||
}
|
||||
if (this.Queues == null || this.Queues.Count == 0) return default(T);
|
||||
isTran = isTran && this.Ado.Transaction == null;
|
||||
if (isTran) this.Ado.BeginTran();
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
var parsmeters = new List<SugarParameter>();
|
||||
var index = 1;
|
||||
if (this.Queues.HasValue())
|
||||
{
|
||||
foreach (var item in Queues)
|
||||
{
|
||||
if (item.Sql == null)
|
||||
item.Sql = string.Empty;
|
||||
if (item.Parameters == null)
|
||||
item.Parameters = new SugarParameter[] { };
|
||||
var itemParsmeters = item.Parameters.OrderByDescending(it => it.ParameterName.Length).ToList();
|
||||
List<SugarParameter> addParameters = new List<SugarParameter>();
|
||||
var itemSql = item.Sql;
|
||||
foreach (var itemParameter in itemParsmeters)
|
||||
{
|
||||
var newName = itemParameter.ParameterName + "_q_" + index;
|
||||
SugarParameter parameter = new SugarParameter(newName, itemParameter.Value);
|
||||
parameter.DbType = itemParameter.DbType;
|
||||
itemSql = UtilMethods.ReplaceSqlParameter(itemSql, itemParameter, newName);
|
||||
addParameters.Add(parameter);
|
||||
}
|
||||
parsmeters.AddRange(addParameters);
|
||||
itemSql = itemSql.TrimEnd(';')+";";
|
||||
sqlBuilder.AppendLine(itemSql);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
this.Queues.Clear();
|
||||
var result = func(sqlBuilder.ToString(), parsmeters);
|
||||
if (isTran) this.Ado.CommitTran();
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (isTran) this.Ado.RollbackTran();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -10,6 +10,6 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CallContext
|
||||
{
|
||||
public static ThreadLocal<List<SqlSugarClient>> ContextList = new ThreadLocal<List<SqlSugarClient>>();
|
||||
public static ThreadLocal<List<SqlSugarContext>> ContextList = new ThreadLocal<List<SqlSugarContext>>();
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,6 @@ namespace SqlSugar
|
||||
internal static Type DicArraySS = typeof(Dictionary<string, string>);
|
||||
internal static Type DicArraySO = typeof(Dictionary<string, object>);
|
||||
|
||||
public static Type SugarType = typeof(SqlSugarClient);
|
||||
public static Type SugarType = typeof(SqlSugarContext);
|
||||
}
|
||||
}
|
||||
|
@ -18,18 +18,18 @@ namespace SqlSugar
|
||||
public SqlSugarException(string message)
|
||||
: base(message){}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context,string message, string sql)
|
||||
public SqlSugarException(SqlSugarContext context,string message, string sql)
|
||||
: base(message) {
|
||||
this.Sql = sql;
|
||||
}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context, string message, string sql, object pars)
|
||||
public SqlSugarException(SqlSugarContext context, string message, string sql, object pars)
|
||||
: base(message) {
|
||||
this.Sql = sql;
|
||||
this.Parametres = pars;
|
||||
}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context, Exception ex, string sql, object pars)
|
||||
public SqlSugarException(SqlSugarContext context, Exception ex, string sql, object pars)
|
||||
: base(ex.Message)
|
||||
{
|
||||
this.Sql = sql;
|
||||
@ -40,7 +40,7 @@ namespace SqlSugar
|
||||
this.Source = ex.Source;
|
||||
}
|
||||
|
||||
public SqlSugarException(SqlSugarClient context, string message, object pars)
|
||||
public SqlSugarException(SqlSugarContext context, string message, object pars)
|
||||
: base(message) {
|
||||
this.Parametres = pars;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user