mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update Core
This commit is contained in:
@@ -9,8 +9,8 @@ namespace SqlSugar
|
||||
{
|
||||
#region Properties
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
private bool IsBackupTable { get; set; }
|
||||
private int MaxBackupDataRows { get; set; }
|
||||
protected bool IsBackupTable { get; set; }
|
||||
protected int MaxBackupDataRows { get; set; }
|
||||
protected virtual int DefultLength { get; set; }
|
||||
#endregion
|
||||
|
||||
|
@@ -35,14 +35,25 @@ namespace SqlSugar
|
||||
#region Core
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
if (InsertBuilder.DbColumnInfoList.HasValue())
|
||||
{
|
||||
var pks = GetPrimaryKeys();
|
||||
foreach (var item in InsertBuilder.DbColumnInfoList)
|
||||
{
|
||||
var isPk = pks.Any(y => y.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || item.IsPrimarykey;
|
||||
if (isPk && item.PropertyType == UtilConstants.GuidType&&item.Value.ObjToString()==Guid.Empty.ToString()) {
|
||||
item.Value = Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = false;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
var result= Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql,null);
|
||||
var result = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -63,8 +74,8 @@ namespace SqlSugar
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
var result= Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql,result);
|
||||
var result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
public virtual long ExecuteReturnBigIdentity()
|
||||
@@ -75,8 +86,8 @@ namespace SqlSugar
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
var result= Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
After(sql,result);
|
||||
var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
public virtual T ExecuteReturnEntity()
|
||||
@@ -92,13 +103,13 @@ namespace SqlSugar
|
||||
var idValue = ExecuteReturnBigIdentity();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
object setValue= 0;
|
||||
object setValue = 0;
|
||||
if (idValue > int.MaxValue)
|
||||
setValue = idValue;
|
||||
else
|
||||
setValue = Convert.ToInt32(idValue);
|
||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result,setValue, null);
|
||||
return idValue>0;
|
||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||
return idValue > 0;
|
||||
}
|
||||
public Task<int> ExecuteCommandAsync()
|
||||
{
|
||||
@@ -181,7 +192,7 @@ namespace SqlSugar
|
||||
public IInsertable<T> InsertColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
var ignoreColumns = InsertBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => ignoreColumns.Any(ig=>ig.Equals(it.PropertyName,StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => ignoreColumns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -314,14 +325,14 @@ namespace SqlSugar
|
||||
}
|
||||
private void SetInsertItemByDic(int i, T item, List<DbColumnInfo> insertItem)
|
||||
{
|
||||
foreach (var column in item as Dictionary<string,object>)
|
||||
foreach (var column in item as Dictionary<string, object>)
|
||||
{
|
||||
var columnInfo = new DbColumnInfo()
|
||||
{
|
||||
Value = column.Value,
|
||||
DbColumnName = column.Key,
|
||||
PropertyName = column.Key,
|
||||
PropertyType = column.Value == null? DBNull.Value.GetType(): UtilMethods.GetUnderType(column.Value.GetType()),
|
||||
PropertyType = column.Value == null ? DBNull.Value.GetType() : UtilMethods.GetUnderType(column.Value.GetType()),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
@@ -428,19 +439,20 @@ namespace SqlSugar
|
||||
return asyncInsertable;
|
||||
}
|
||||
|
||||
private void After(string sql,long? result)
|
||||
private void After(string sql, long? result)
|
||||
{
|
||||
if (this.IsEnableDiffLogEvent)
|
||||
{
|
||||
var parameters = InsertBuilder.Parameters;
|
||||
if (parameters == null)
|
||||
parameters = new List<SugarParameter>();
|
||||
diffModel.AfterData = GetDiffTable(sql,result);
|
||||
diffModel.AfterData = GetDiffTable(sql, result);
|
||||
diffModel.Time = this.Context.Ado.SqlExecutionTime;
|
||||
if (this.Context.Ado.DiffLogEvent != null)
|
||||
this.Context.Ado.DiffLogEvent(diffModel);
|
||||
}
|
||||
if (this.RemoveCacheFunc != null) {
|
||||
if (this.RemoveCacheFunc != null)
|
||||
{
|
||||
this.RemoveCacheFunc();
|
||||
}
|
||||
}
|
||||
@@ -456,22 +468,24 @@ namespace SqlSugar
|
||||
diffModel.Parameters = parameters.ToArray();
|
||||
}
|
||||
}
|
||||
private List<DiffLogTableInfo> GetDiffTable(string sql,long? identity)
|
||||
private List<DiffLogTableInfo> GetDiffTable(string sql, long? identity)
|
||||
{
|
||||
List<SugarParameter> parameters = new List<SugarParameter>();
|
||||
List<DiffLogTableInfo> result = new List<DiffLogTableInfo>();
|
||||
var whereSql = string.Empty;
|
||||
List<IConditionalModel> cons = new List<IConditionalModel>();
|
||||
if (identity != null&&identity>0 && GetIdentityKeys().HasValue())
|
||||
if (identity != null && identity > 0 && GetIdentityKeys().HasValue())
|
||||
{
|
||||
var fieldName = GetIdentityKeys().Last();
|
||||
cons.Add(new ConditionalModel() { ConditionalType=ConditionalType.Equal, FieldName= fieldName, FieldValue=identity.ToString() });
|
||||
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fieldName, FieldValue = identity.ToString() });
|
||||
}
|
||||
else {
|
||||
foreach(var item in this.EntityInfo.Columns.Where(it => it.IsIgnore == false&&GetPrimaryKeys().Any(pk=>pk.Equals(it.DbColumnName,StringComparison.CurrentCultureIgnoreCase)))) {
|
||||
else
|
||||
{
|
||||
foreach (var item in this.EntityInfo.Columns.Where(it => it.IsIgnore == false && GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))))
|
||||
{
|
||||
var fielddName = item.DbColumnName;
|
||||
var fieldValue = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null).ObjToString();
|
||||
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fielddName, FieldValue =fieldValue });
|
||||
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fielddName, FieldValue = fieldValue });
|
||||
}
|
||||
}
|
||||
Check.Exception(cons.IsNullOrEmpty(), "Insertable.EnableDiffLogEvent need primary key");
|
||||
@@ -499,7 +513,8 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DiffLogTableInfo diffTable = new DiffLogTableInfo();
|
||||
diffTable.TableName = this.EntityInfo.DbTableName;
|
||||
diffTable.TableDescription = this.EntityInfo.TableDescription;
|
||||
|
@@ -24,6 +24,7 @@ namespace SqlSugar
|
||||
public MappingTableList QueryableMappingTableList { get; set; }
|
||||
public Action<T> MapperAction { get; set; }
|
||||
public Action<T, MapperCache<T>> MapperActionWithCache { get; set; }
|
||||
public List<Action<List<T>>> Mappers { get; set; }
|
||||
public bool IsCache { get; set; }
|
||||
public int CacheTime { get; set; }
|
||||
public bool IsAs { get; set; }
|
||||
@@ -78,7 +79,8 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction) {
|
||||
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction)
|
||||
{
|
||||
this.MapperAction = mapperAction;
|
||||
return this;
|
||||
}
|
||||
@@ -87,6 +89,14 @@ namespace SqlSugar
|
||||
this.MapperActionWithCache = mapperAction;
|
||||
return this;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mapperField)
|
||||
{
|
||||
return _Mapper<TObject>(mapperObject, mapperField);
|
||||
}
|
||||
public virtual ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mapperField)
|
||||
{
|
||||
return _Mapper<TObject>(mapperObject, mapperField);
|
||||
}
|
||||
|
||||
public virtual ISugarQueryable<T> AddParameters(object parameters)
|
||||
{
|
||||
@@ -128,6 +138,70 @@ namespace SqlSugar
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public ISugarQueryable<T> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
return WhereClass(new List<ClassType>() { whereClass },ignoreDefaultValue);
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public ISugarQueryable<T> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
if (whereClassTypes.HasValue())
|
||||
{
|
||||
var columns = this.Context.EntityMaintenance.GetEntityInfo<ClassType>().Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
List<IConditionalModel> whereModels = new List<IConditionalModel>();
|
||||
foreach (var item in whereClassTypes)
|
||||
{
|
||||
var cons = new ConditionalCollections();
|
||||
foreach (var column in columns)
|
||||
{
|
||||
|
||||
var value = column.PropertyInfo.GetValue(item, null);
|
||||
WhereType WhereType = WhereType.And;
|
||||
var isNotNull = ignoreDefaultValue == false&&value != null ;
|
||||
var isNotNullAndDefault = ignoreDefaultValue&& value!=null && value.ObjToString() != UtilMethods.DefaultForType(column.PropertyInfo.PropertyType).ObjToString();
|
||||
if (isNotNull||isNotNullAndDefault)
|
||||
{
|
||||
if (cons.ConditionalList == null)
|
||||
{
|
||||
cons.ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>();
|
||||
if (QueryBuilder.WhereInfos.IsNullOrEmpty() && whereModels.IsNullOrEmpty())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
WhereType = WhereType.Or;
|
||||
}
|
||||
|
||||
}
|
||||
cons.ConditionalList.Add(new KeyValuePair<WhereType, ConditionalModel>(WhereType, new ConditionalModel()
|
||||
{
|
||||
ConditionalType = ConditionalType.Equal,
|
||||
FieldName = column.DbColumnName,
|
||||
FieldValue = value.ObjToString()
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (cons.HasValue())
|
||||
{
|
||||
whereModels.Add(cons);
|
||||
}
|
||||
}
|
||||
this.Where(whereModels);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public virtual ISugarQueryable<T> Where(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Where(expression);
|
||||
@@ -197,8 +271,9 @@ namespace SqlSugar
|
||||
Where(SqlBuilder.SqlFalse);
|
||||
return this;
|
||||
}
|
||||
if (pkValues.Length == 1&& pkValues.First().GetType().FullName.IsCollectionsList()) {
|
||||
var newValues =new List<object>();
|
||||
if (pkValues.Length == 1 && pkValues.First().GetType().FullName.IsCollectionsList()|| pkValues.First() is IEnumerable)
|
||||
{
|
||||
var newValues = new List<object>();
|
||||
foreach (var item in pkValues.First() as IEnumerable)
|
||||
{
|
||||
newValues.Add(item);
|
||||
@@ -457,7 +532,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual ISugarQueryable<TResult> Select<TResult>()
|
||||
{
|
||||
var isJoin = this.QueryBuilder.JoinExpression!=null;
|
||||
var isJoin = this.QueryBuilder.JoinExpression != null;
|
||||
if (isJoin)
|
||||
{
|
||||
var selectValue = new SugarMapper(this.Context).GetSelectValue<TResult>(this.QueryBuilder);
|
||||
@@ -484,7 +559,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T> MergeTable()
|
||||
{
|
||||
Check.Exception(this.MapperAction != null||this.MapperActionWithCache!=null, "'Mapper’ needs to be written after ‘MergeTable’ ");
|
||||
Check.Exception(this.MapperAction != null || this.MapperActionWithCache != null, "'Mapper’ needs to be written after ‘MergeTable’ ");
|
||||
Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Queryable.Select Method .");
|
||||
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList ");
|
||||
ToSqlBefore();
|
||||
@@ -1004,7 +1079,7 @@ namespace SqlSugar
|
||||
}
|
||||
protected ISugarQueryable<TResult> _Select<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression,"Select");
|
||||
QueryBuilder.CheckExpression(expression, "Select");
|
||||
this.Context.InitMppingInfo<TResult>();
|
||||
var result = InstanceFactory.GetQueryable<TResult>(this.Context.CurrentConnectionConfig);
|
||||
result.Context = this.Context;
|
||||
@@ -1027,8 +1102,8 @@ namespace SqlSugar
|
||||
if ((expression as LambdaExpression).Body is NewExpression)
|
||||
{
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.ArraySingle : ResolveExpressType.ArrayMultiple);
|
||||
var items = lamResult.GetResultString().Split(',').Where(it => it.HasValue()).Select(it=> it + UtilConstants.Space + type.ToString().ToUpper()).ToList();
|
||||
OrderBy(string.Join(",",items));
|
||||
var items = lamResult.GetResultString().Split(',').Where(it => it.HasValue()).Select(it => it + UtilConstants.Space + type.ToString().ToUpper()).ToList();
|
||||
OrderBy(string.Join(",", items));
|
||||
return this;
|
||||
}
|
||||
else
|
||||
@@ -1168,6 +1243,20 @@ namespace SqlSugar
|
||||
|
||||
protected void _Mapper<TResult>(List<TResult> result)
|
||||
{
|
||||
if (this.Mappers.HasValue())
|
||||
{
|
||||
foreach (var mapper in this.Mappers)
|
||||
{
|
||||
if (typeof(TResult) == typeof(T))
|
||||
{
|
||||
mapper(result.Select(it => (T)Convert.ChangeType(it, typeof(T))).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.MapperAction != null)
|
||||
{
|
||||
foreach (TResult item in result)
|
||||
@@ -1176,8 +1265,9 @@ namespace SqlSugar
|
||||
{
|
||||
this.MapperAction((T)Convert.ChangeType(item, typeof(T)));
|
||||
}
|
||||
else {
|
||||
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName,typeof(T).FullName);
|
||||
else
|
||||
{
|
||||
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1186,18 +1276,147 @@ namespace SqlSugar
|
||||
if (typeof(TResult) == typeof(T))
|
||||
{
|
||||
var list = (List<T>)Convert.ChangeType(result, typeof(List<T>));
|
||||
var mapperCache = new MapperCache<T>(list,this.Context);
|
||||
var mapperCache = new MapperCache<T>(list, this.Context);
|
||||
foreach (T item in list)
|
||||
{
|
||||
this.MapperActionWithCache(item, mapperCache);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ISugarQueryable<T> _Mapper<TObject>(Expression mapperObject, Expression mapperField)
|
||||
{
|
||||
if ((mapperObject as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
mapperObject = ((mapperObject as LambdaExpression).Body as UnaryExpression).Operand;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapperObject = (mapperObject as LambdaExpression).Body;
|
||||
}
|
||||
if ((mapperField as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
mapperField = ((mapperField as LambdaExpression).Body as UnaryExpression).Operand;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapperField = (mapperField as LambdaExpression).Body;
|
||||
}
|
||||
Check.Exception(mapperObject is MemberExpression == false || mapperField is MemberExpression == false, ".Mapper() parameter error");
|
||||
var mapperObjectExp = mapperObject as MemberExpression;
|
||||
var mapperFieldExp = mapperField as MemberExpression;
|
||||
Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error");
|
||||
var objType = mapperObjectExp.Type;
|
||||
var filedType = mapperFieldExp.Expression.Type;
|
||||
Check.Exception(objType != typeof(TObject) && objType != typeof(List<TObject>), ".Mapper() parameter error");
|
||||
if (objType == typeof(List<TObject>))
|
||||
{
|
||||
objType = typeof(TObject);
|
||||
}
|
||||
var filedName = mapperFieldExp.Member.Name;
|
||||
var objName = mapperObjectExp.Member.Name;
|
||||
var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType);
|
||||
var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType);
|
||||
var isSelf = filedType == typeof(T);
|
||||
if (Mappers == null)
|
||||
Mappers = new List<Action<List<T>>>();
|
||||
if (isSelf)
|
||||
{
|
||||
Action<List<T>> mapper = (entitys) =>
|
||||
{
|
||||
if (entitys.IsNullOrEmpty()) return;
|
||||
var entity = entitys.First();
|
||||
var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList();
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
{
|
||||
FieldName=whereCol.DbColumnName,
|
||||
ConditionalType= ConditionalType.In,
|
||||
FieldValue=string.Join(",",inValues.Distinct())
|
||||
}
|
||||
};
|
||||
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(filedName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
{
|
||||
setObject.SetValue(item, setValue.ToList(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
setObject.SetValue(item, setValue.FirstOrDefault(), null);
|
||||
}
|
||||
}
|
||||
};
|
||||
Mappers.Add(mapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
Action<List<T>> mapper = (entitys) =>
|
||||
{
|
||||
if (entitys.IsNullOrEmpty()) return;
|
||||
var entity = entitys.First();
|
||||
var tEntity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (whereCol == null)
|
||||
{
|
||||
whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true);
|
||||
}
|
||||
if (whereCol == null)
|
||||
{
|
||||
Check.Exception(true, ".Mapper() parameter error");
|
||||
}
|
||||
List<string> inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList();
|
||||
var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == filedName).DbColumnName;
|
||||
List<IConditionalModel> wheres = new List<IConditionalModel>()
|
||||
{
|
||||
new ConditionalModel()
|
||||
{
|
||||
FieldName=dbColumnName,
|
||||
ConditionalType= ConditionalType.In,
|
||||
FieldValue=string.Join(",",inValues)
|
||||
}
|
||||
};
|
||||
var list = this.Context.Queryable<TObject>().Where(wheres).ToList();
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null);
|
||||
var setValue = list.Where(x => x.GetType().GetProperty(filedName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList();
|
||||
var setObject = item.GetType().GetProperty(objName);
|
||||
if (setObject.PropertyType.FullName.IsCollectionsList())
|
||||
{
|
||||
setObject.SetValue(item, setValue.ToList(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
setObject.SetValue(item, setValue.FirstOrDefault(), null);
|
||||
}
|
||||
}
|
||||
};
|
||||
Mappers.Add(mapper);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected int GetCount()
|
||||
{
|
||||
var sql = string.Empty;
|
||||
@@ -1330,7 +1549,7 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.Take = this.QueryBuilder.Take;
|
||||
asyncQueryableBuilder.Skip = this.QueryBuilder.Skip;
|
||||
asyncQueryableBuilder.SelectValue = this.QueryBuilder.SelectValue;
|
||||
asyncQueryableBuilder.WhereInfos =this.Context.Utilities.TranslateCopy(this.QueryBuilder.WhereInfos);
|
||||
asyncQueryableBuilder.WhereInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.WhereInfos);
|
||||
asyncQueryableBuilder.EasyJoinInfos = this.QueryBuilder.EasyJoinInfos;
|
||||
asyncQueryableBuilder.JoinQueryInfos = this.QueryBuilder.JoinQueryInfos;
|
||||
asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex;
|
||||
@@ -1394,6 +1613,27 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -1518,7 +1758,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T,T2, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, T2, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1527,7 +1767,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T,T2, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, T2, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1536,7 +1776,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T,T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2> In<FieldType>(Expression<Func<T, T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
@@ -1545,9 +1785,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T,T2> Clone()
|
||||
public new ISugarQueryable<T, T2> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T,T2>((t,t2)=>new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2>((t, t2) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -1781,6 +2021,27 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
@@ -1828,7 +2089,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T,T2, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1837,7 +2098,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T,T2, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1846,14 +2107,14 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T,T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1862,7 +2123,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -1871,7 +2132,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2, T3> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
@@ -1880,9 +2141,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2,T3> Clone()
|
||||
public new ISugarQueryable<T, T2, T3> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2,T3>((t, t2,t3) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3>((t, t2, t3) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -2028,6 +2289,27 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -2195,7 +2477,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T,T2, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2204,7 +2486,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T,T2, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2213,14 +2495,14 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T,T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2229,7 +2511,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2238,14 +2520,14 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2,T3, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3,T4, object>> expression, params FieldType[] inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, T4, object>> expression, params FieldType[] inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2254,7 +2536,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3,T4, object>> expression, List<FieldType> inValues)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, T4, object>> expression, List<FieldType> inValues)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "In");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
@@ -2263,7 +2545,7 @@ namespace SqlSugar
|
||||
In(fieldName, inValues);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3,T4, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
public ISugarQueryable<T, T2, T3, T4> In<FieldType>(Expression<Func<T, T2, T3, T4, object>> expression, ISugarQueryable<FieldType> childQueryExpression)
|
||||
{
|
||||
var sqlObj = childQueryExpression.ToSql();
|
||||
_InQueryable(expression, sqlObj);
|
||||
@@ -2273,9 +2555,9 @@ namespace SqlSugar
|
||||
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2,T3,T4> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2,T3,T4>((t, t2,t3,t4) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4>((t, t2, t3, t4) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -2433,6 +2715,29 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T,T2, T3, T4, T5> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T,T2, T3, T4, T5> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -2591,9 +2896,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4,T5> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4,T5>((t, t2, t3, t4,t5) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5>((t, t2, t3, t4, t5) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -2763,6 +3068,28 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -2819,6 +3146,48 @@ namespace SqlSugar
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, string orderFileds)
|
||||
{
|
||||
if (isOrderBy)
|
||||
base.OrderBy(orderFileds);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GroupBy
|
||||
@@ -2899,9 +3268,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5,T6>((t, t2, t3, t4, t5,T6) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6>((t, t2, t3, t4, t5, T6) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -3083,6 +3452,27 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -3186,7 +3576,54 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, string orderFileds)
|
||||
{
|
||||
if (isOrderBy)
|
||||
base.OrderBy(orderFileds);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
@@ -3234,9 +3671,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6,T7>((t, t2, t3, t4, t5, T6,t7) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7>((t, t2, t3, t4, t5, T6, t7) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -3430,6 +3867,27 @@ namespace SqlSugar
|
||||
this.Where<T>(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
base.WhereClass(whereClass, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereClass<ClassType>(List<ClassType> whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new()
|
||||
{
|
||||
|
||||
base.WhereClass(whereClassTypes, ignoreDefaultValue);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -3504,6 +3962,60 @@ namespace SqlSugar
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, string orderFileds)
|
||||
{
|
||||
if (isOrderBy)
|
||||
base.OrderBy(orderFileds);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object>> expression, OrderByType type = OrderByType.Asc)
|
||||
{
|
||||
if (isOrderBy)
|
||||
_OrderBy(expression, type);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GroupBy
|
||||
@@ -3595,9 +4107,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7,T8>((t, t2, t3, t4, t5, T6, t7,t8) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8>((t, t2, t3, t4, t5, T6, t7, t8) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -3980,9 +4492,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8,T9>((t, t2, t3, t4, t5, T6, t7, t8,t9) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>((t, t2, t3, t4, t5, T6, t7, t8, t9) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -4389,9 +4901,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10>((t, t2, t3, t4, t5, T6, t7, t8, t9,t10) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>((t, t2, t3, t4, t5, T6, t7, t8, t9, t10) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -4822,9 +5334,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>((t, t2, t3, t4, t5, T6, t7, t8, t9,t10,t11) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
@@ -5281,9 +5793,9 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> Clone()
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12>((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11,t12) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11, t12) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
|
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class SaveableProvider<T> : ISaveable<T> where T : class, new()
|
||||
{
|
||||
internal SaveableProvider(SqlSugarClient context,List<T> saveObjects)
|
||||
{
|
||||
this.saveObjects = saveObjects;
|
||||
this.Context = context;
|
||||
}
|
||||
internal SaveableProvider(SqlSugarClient context, T saveObject)
|
||||
{
|
||||
this.saveObjects = new List<T>() { saveObject };
|
||||
this.Context = context;
|
||||
}
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public List<T> saveObjects = new List<T>();
|
||||
public List<T> existsObjects = null;
|
||||
public List<T> insertObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
var pks = GetPrimaryKeys();
|
||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkValues = saveObjects.Select(it=>it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it,null));
|
||||
if(existsObjects==null)
|
||||
existsObjects=this.Context.Queryable<T>().In(pkValues).ToList();
|
||||
return saveObjects.Where(it=>!
|
||||
existsObjects.Any(e=>
|
||||
e.GetType().GetProperty(pkInfo.PropertyName).GetValue(e,null).ObjToString()
|
||||
==
|
||||
it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null).ObjToString())).ToList();
|
||||
}
|
||||
}
|
||||
public List<T> updatObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
var pks = GetPrimaryKeys();
|
||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkValues = saveObjects.Select(it => it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null));
|
||||
if (existsObjects == null)
|
||||
existsObjects = this.Context.Queryable<T>().In(pkValues).ToList();
|
||||
return saveObjects.Where(it =>
|
||||
existsObjects.Any(e =>
|
||||
e.GetType().GetProperty(pkInfo.PropertyName).GetValue(e, null).ObjToString()
|
||||
==
|
||||
it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null).ObjToString())).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public IInsertable<T> insertable { get; set; }
|
||||
public IUpdateable<T> updateable { get; set; }
|
||||
|
||||
public EntityInfo EntityInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
LoadInsertable();
|
||||
LoadUpdateable();
|
||||
var insertCount = 0;
|
||||
var updateCount = 0;
|
||||
if (insertable != null)
|
||||
{
|
||||
insertCount = insertable.ExecuteCommand();
|
||||
}
|
||||
if (updateable != null)
|
||||
{
|
||||
updateCount = updateable.ExecuteCommand();
|
||||
}
|
||||
return updateCount + insertCount;
|
||||
}
|
||||
|
||||
public T ExecuteReturnEntity()
|
||||
{
|
||||
LoadInsertable();
|
||||
LoadUpdateable();
|
||||
if (insertable != null)
|
||||
insertable.ExecuteCommandIdentityIntoEntity();
|
||||
if (updateable != null)
|
||||
updateable.ExecuteCommand();
|
||||
return saveObjects.First();
|
||||
}
|
||||
|
||||
public List<T> ExecuteReturnList()
|
||||
{
|
||||
LoadInsertable();
|
||||
LoadUpdateable();
|
||||
if (insertable != null)
|
||||
insertable.ExecuteCommand();
|
||||
if (updateable != null)
|
||||
updateable.ExecuteCommand();
|
||||
return saveObjects;
|
||||
}
|
||||
public ISaveable<T> InsertColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
LoadInsertable();
|
||||
if (this.insertable != null)
|
||||
{
|
||||
this.insertable.InsertColumns(columns);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISaveable<T> InsertIgnoreColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
LoadInsertable();
|
||||
if (this.insertable != null)
|
||||
{
|
||||
this.insertable.IgnoreColumns(columns);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISaveable<T> UpdateColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
LoadUpdateable();
|
||||
if (this.updateable != null)
|
||||
{
|
||||
this.updateable.UpdateColumns(columns);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISaveable<T> UpdateIgnoreColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
LoadUpdateable();
|
||||
if (this.updateable != null)
|
||||
{
|
||||
this.updateable.IgnoreColumns(columns);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected virtual List<string> GetPrimaryKeys()
|
||||
{
|
||||
if (this.Context.IsSystemTablesConfig)
|
||||
{
|
||||
return this.Context.DbMaintenance.GetPrimaries(this.Context.EntityMaintenance.GetTableName(this.EntityInfo.EntityName));
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.EntityInfo.Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
}
|
||||
private void LoadInsertable()
|
||||
{
|
||||
var temp = insertObjects;
|
||||
if (insertable == null && temp.HasValue())
|
||||
insertable = this.Context.Insertable<T>(temp);
|
||||
}
|
||||
private void LoadUpdateable()
|
||||
{
|
||||
var temp = updatObjects;
|
||||
if (updateable == null && temp.HasValue())
|
||||
updateable = this.Context.Updateable<T>(temp);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -9,5 +9,9 @@ namespace SqlSugar
|
||||
{
|
||||
public bool IsAutoRemoveDataCache { get; set; }
|
||||
public bool IsWithNoLockQuery { get; set; }
|
||||
/// <summary>
|
||||
/// Some MYSQL databases do not support NVarchar set true
|
||||
/// </summary>
|
||||
public bool MySqlDisableNarvchar { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -122,6 +122,8 @@ namespace SqlSugar
|
||||
{
|
||||
ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true);
|
||||
copyContext.Index = this.Index;
|
||||
copyContext.InitMappingInfo = this.InitMappingInfo;
|
||||
copyContext.RefreshMapping = this.RefreshMapping;
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
return copyContext;
|
||||
}
|
||||
@@ -134,6 +136,8 @@ namespace SqlSugar
|
||||
copyContext.MappingTables = this.MappingTables;
|
||||
copyContext.IgnoreComumnList = this.IgnoreComumnList;
|
||||
copyContext.SqlFuncServices = this.SqlFuncServices;
|
||||
copyContext.InitMappingInfo = this.InitMappingInfo;
|
||||
copyContext.RefreshMapping = this.RefreshMapping;
|
||||
return copyContext;
|
||||
}
|
||||
#endregion
|
||||
|
@@ -396,6 +396,9 @@ namespace SqlSugar
|
||||
}
|
||||
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue()) {
|
||||
this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
|
@@ -218,7 +218,7 @@ namespace SqlSugar
|
||||
if (this.Expression.Type == UtilConstants.DateType && this.Expression.ToString() == "DateTime.Now")
|
||||
{
|
||||
this.Expression = expression;
|
||||
var parameterName=base.AppendParameter(ExpressionTool.GetMemberValue(expression.Member, expression));
|
||||
var parameterName = base.AppendParameter(ExpressionTool.GetMemberValue(expression.Member, expression));
|
||||
base.AppendMember(parameter, isLeft, parameterName);
|
||||
}
|
||||
else
|
||||
@@ -254,6 +254,14 @@ namespace SqlSugar
|
||||
|
||||
private void ResolveLength(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
||||
{
|
||||
if (parameter.Context.ResolveType == ResolveExpressType.FieldSingle)
|
||||
{
|
||||
parameter.Context.ResolveType = ResolveExpressType.WhereSingle;
|
||||
}
|
||||
if (parameter.Context.ResolveType == ResolveExpressType.FieldMultiple)
|
||||
{
|
||||
parameter.Context.ResolveType = ResolveExpressType.WhereMultiple;
|
||||
}
|
||||
var oldCommonTempDate = parameter.CommonTempData;
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
this.Expression = expression.Expression;
|
||||
|
@@ -124,8 +124,9 @@ namespace SqlSugar
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
var subSql = base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString());
|
||||
if (ResolveExpressType.Update == this.Context.ResolveType) {
|
||||
subSql = Regex.Replace(subSql,@" \[\w+?\]\.",this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
||||
if (ResolveExpressType.Update == this.Context.ResolveType)
|
||||
{
|
||||
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
||||
}
|
||||
parameter.Context.Result.Append(subSql);
|
||||
});
|
||||
|
@@ -47,6 +47,18 @@ namespace SqlSugar
|
||||
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
|
||||
}
|
||||
}
|
||||
else if (context.Expression.GetType().Name == "MethodBinaryExpression")
|
||||
{
|
||||
|
||||
var subExp = (context.Expression as BinaryExpression).Left is MethodCallExpression ? (context.Expression as BinaryExpression).Left : (context.Expression as BinaryExpression).Right;
|
||||
var meExp = ((subExp as MethodCallExpression).Object as MethodCallExpression).Arguments[0] as LambdaExpression;
|
||||
var selfParameterName = meExp.Parameters.First().Name;
|
||||
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression).Expression as ParameterExpression).Name;
|
||||
if (context.SingleTableNameSubqueryShortName == selfParameterName)
|
||||
{
|
||||
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Exception(true, "I'm sorry I can't parse the current expression");
|
||||
|
@@ -456,7 +456,11 @@ namespace SqlSugar
|
||||
var index = item.ConditionalList.IndexOf(con);
|
||||
var isFirst = index == 0;
|
||||
var isLast = index == (item.ConditionalList.Count - 1);
|
||||
if (isFirst)
|
||||
if (models.IndexOf(item) == 0 &&index==0&& beginIndex == 0)
|
||||
{
|
||||
builder.AppendFormat(" ( ");
|
||||
|
||||
}else if (isFirst)
|
||||
{
|
||||
builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper());
|
||||
}
|
||||
|
@@ -21,11 +21,26 @@ namespace SqlSugar
|
||||
ISugarQueryable<T> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
ISugarQueryable<T> Mapper(Action<T> mapperAction);
|
||||
ISugarQueryable<T> Mapper(Action<T, MapperCache<T>> mapperAction);
|
||||
ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mapperField);
|
||||
ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mapperField);
|
||||
ISugarQueryable<T> AddParameters(object parameters);
|
||||
ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
|
||||
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
|
||||
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
ISugarQueryable<T> WhereClass<ClassType>(ClassType whereClass,bool ignoreDefaultValue=false)where ClassType: class,new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
ISugarQueryable<T> WhereClass<ClassType>(List<ClassType> whereClassList,bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
|
||||
ISugarQueryable<T> Where(Expression<Func<T, bool>> expression);
|
||||
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
||||
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
||||
@@ -142,6 +157,18 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2> Where(string whereString, object whereObj = null);
|
||||
new ISugarQueryable<T, T2> WhereIF(bool isWhere, string whereString, object whereObj = null);
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T,T2> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T,T2> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -210,6 +237,19 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2,T3> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2,T3> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -288,6 +328,19 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3, T4> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3, T4> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2,T3,T4> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2,T3,T4> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -378,6 +431,19 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -456,6 +522,20 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -473,6 +553,13 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> OrderBy(Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> OrderBy(Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, string orderFileds);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5,T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5,T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
#endregion
|
||||
|
||||
#region GroupBy
|
||||
@@ -533,6 +620,20 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -552,6 +653,14 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderBy(Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, string orderFileds);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6,T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6,T7, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
#endregion
|
||||
|
||||
#region GroupBy
|
||||
@@ -615,6 +724,20 @@ namespace SqlSugar
|
||||
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Where(string whereString, object parameters = null);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClass"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereClass<ClassType>(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
/// <summary>
|
||||
/// if a property that is not empty is a condition
|
||||
/// </summary>
|
||||
/// <param name="whereClassTypes"></param>
|
||||
/// <returns></returns>
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereClass<ClassType>(List<ClassType> whereClassList, bool ignoreDefaultValue = false) where ClassType : class, new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Select
|
||||
@@ -636,6 +759,15 @@ namespace SqlSugar
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderBy(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, string orderFileds);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, T7, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> OrderByIF(bool isOrderBy, Expression<Func<T, T2, T3, T4, T5, T6, T7,T8, object>> expression, OrderByType type = OrderByType.Asc);
|
||||
#endregion
|
||||
|
||||
#region GroupBy
|
||||
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial interface ISaveable<T> where T : class, new()
|
||||
{
|
||||
int ExecuteCommand();
|
||||
T ExecuteReturnEntity();
|
||||
List<T> ExecuteReturnList();
|
||||
ISaveable<T> InsertColumns(Expression<Func<T, object>> columns);
|
||||
ISaveable<T> InsertIgnoreColumns(Expression<Func<T, object>> columns);
|
||||
ISaveable<T> UpdateColumns(Expression<Func<T, object>> columns);
|
||||
ISaveable<T> UpdateIgnoreColumns(Expression<Func<T, object>> columns);
|
||||
}
|
||||
}
|
@@ -27,6 +27,11 @@ namespace SqlSugar
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||
{
|
||||
n = "";
|
||||
}
|
||||
if (value == null)
|
||||
{
|
||||
return "NULL";
|
||||
@@ -58,11 +63,11 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
||||
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + GetString(value) + "'";
|
||||
return n+"'" + GetString(value) + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -90,6 +90,11 @@ namespace SqlSugar
|
||||
}
|
||||
public override object FormatValue(object value)
|
||||
{
|
||||
var n = "N";
|
||||
if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||
{
|
||||
n = "";
|
||||
}
|
||||
if (value == null)
|
||||
{
|
||||
return "NULL";
|
||||
@@ -121,11 +126,11 @@ namespace SqlSugar
|
||||
}
|
||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||
{
|
||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
||||
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "N'" + GetString(value) + "'";
|
||||
return n+"'" + GetString(value) + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,21 +9,83 @@ namespace SqlSugar
|
||||
{
|
||||
public override void ExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
var tableName = GetTableName(entityInfo);
|
||||
string backupName = tableName + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
foreach (var item in entityInfo.Columns.Where(it => it.IsIgnore == false))
|
||||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
|
||||
var tableName = GetTableName(entityInfo);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName);
|
||||
ConvertColumns(dbColumns);
|
||||
var entityColumns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
var dropColumns = dbColumns
|
||||
.Where(dc => !entityColumns.Any(ec => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.Where(dc => !entityColumns.Any(ec => dc.DbColumnName.Equals(ec.DbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.ToList();
|
||||
var addColumns = entityColumns
|
||||
.Where(ec => ec.OldDbColumnName.IsNullOrEmpty() || !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.Where(ec => !dbColumns.Any(dc => ec.DbColumnName.Equals(dc.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
//var alterColumns = entityColumns
|
||||
// .Where(ec => !dbColumns.Any(dc => dc.DbColumnName.Equals(ec.OldDbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
// .Where(ec =>
|
||||
// dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
|
||||
// && ((!UtilMethods.GetUnderType(ec.PropertyInfo).IsEnum() && UtilMethods.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
|
||||
|
||||
// IsSamgeType(ec, dc)))).ToList();
|
||||
var renameColumns = entityColumns
|
||||
.Where(it => !string.IsNullOrEmpty(it.OldDbColumnName))
|
||||
.Where(entityColumn => dbColumns.Any(dbColumn => entityColumn.OldDbColumnName.Equals(dbColumn.DbColumnName, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.ToList();
|
||||
|
||||
|
||||
var isChange = false;
|
||||
foreach (var item in addColumns)
|
||||
{
|
||||
DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||
columns.Add(dbColumnInfo);
|
||||
this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
isChange = true;
|
||||
}
|
||||
foreach (var item in dropColumns)
|
||||
{
|
||||
//this.Context.DbMaintenance.DropColumn(tableName, item.DbColumnName);
|
||||
//isChange = true;
|
||||
}
|
||||
//foreach (var item in alterColumns)
|
||||
//{
|
||||
// //this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||
// //isChange = true;
|
||||
//}
|
||||
foreach (var item in renameColumns)
|
||||
{
|
||||
throw new NotSupportedException("rename Column");
|
||||
}
|
||||
|
||||
foreach (var item in entityColumns)
|
||||
{
|
||||
var dbColumn = dbColumns.FirstOrDefault(dc => dc.DbColumnName.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (dbColumn == null) continue;
|
||||
bool pkDiff, idEntityDiff;
|
||||
KeyAction(item, dbColumn, out pkDiff, out idEntityDiff);
|
||||
if (dbColumn != null && pkDiff && !idEntityDiff)
|
||||
{
|
||||
var isAdd = item.IsPrimarykey;
|
||||
if (isAdd)
|
||||
{
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.DbMaintenance.DropConstraint(tableName, string.Format("PK_{0}_{1}", tableName, item.DbColumnName));
|
||||
}
|
||||
}
|
||||
else if (pkDiff || idEntityDiff)
|
||||
{
|
||||
ChangeKey(entityInfo, tableName, item);
|
||||
}
|
||||
}
|
||||
if (isChange && base.IsBackupTable)
|
||||
{
|
||||
this.Context.DbMaintenance.BackupTable(tableName, tableName + DateTime.Now.ToString("yyyyMMddHHmmss"), MaxBackupDataRows);
|
||||
}
|
||||
}
|
||||
this.Context.DbMaintenance.BackupTable(tableName, backupName, int.MaxValue);
|
||||
this.Context.DbMaintenance.DropTable(tableName);
|
||||
this.Context.DbMaintenance.CreateTable(tableName,columns);
|
||||
}
|
||||
public override void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
|
@@ -47,7 +47,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
return "ALTER TABLE {0} ADD COLUMN {1} {2}{3}";
|
||||
}
|
||||
}
|
||||
protected override string AlterColumnToTableSql
|
||||
|
@@ -561,6 +561,17 @@ namespace SqlSugar
|
||||
}
|
||||
#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
|
||||
{
|
||||
|
@@ -8,6 +8,15 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = @"DataSource=F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\Src\Asp.NetCore2\SqlSeverTest\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
||||
public static string GetCurrentProjectPath
|
||||
{
|
||||
|
||||
get
|
||||
{
|
||||
return Environment.CurrentDirectory.Replace(@"\bin\Debug", "");
|
||||
}
|
||||
}
|
||||
public static string ConnectionString = @"DataSource=" + GetCurrentProjectPath + @"\DataBase\SqlSugar4xTest.sqlite";
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user