mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Update Core
This commit is contained in:
@@ -9,8 +9,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
public virtual SqlSugarClient Context { get; set; }
|
public virtual SqlSugarClient Context { get; set; }
|
||||||
private bool IsBackupTable { get; set; }
|
protected bool IsBackupTable { get; set; }
|
||||||
private int MaxBackupDataRows { get; set; }
|
protected int MaxBackupDataRows { get; set; }
|
||||||
protected virtual int DefultLength { get; set; }
|
protected virtual int DefultLength { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@@ -35,6 +35,17 @@ namespace SqlSugar
|
|||||||
#region Core
|
#region Core
|
||||||
public virtual int ExecuteCommand()
|
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;
|
InsertBuilder.IsReturnIdentity = false;
|
||||||
PreToSql();
|
PreToSql();
|
||||||
AutoRemoveDataCache();
|
AutoRemoveDataCache();
|
||||||
@@ -440,7 +451,8 @@ namespace SqlSugar
|
|||||||
if (this.Context.Ado.DiffLogEvent != null)
|
if (this.Context.Ado.DiffLogEvent != null)
|
||||||
this.Context.Ado.DiffLogEvent(diffModel);
|
this.Context.Ado.DiffLogEvent(diffModel);
|
||||||
}
|
}
|
||||||
if (this.RemoveCacheFunc != null) {
|
if (this.RemoveCacheFunc != null)
|
||||||
|
{
|
||||||
this.RemoveCacheFunc();
|
this.RemoveCacheFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,8 +479,10 @@ namespace SqlSugar
|
|||||||
var fieldName = GetIdentityKeys().Last();
|
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 {
|
else
|
||||||
foreach(var item in this.EntityInfo.Columns.Where(it => it.IsIgnore == false&&GetPrimaryKeys().Any(pk=>pk.Equals(it.DbColumnName,StringComparison.CurrentCultureIgnoreCase)))) {
|
{
|
||||||
|
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 fielddName = item.DbColumnName;
|
||||||
var fieldValue = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.PropertyName).PropertyInfo.GetValue(this.InsertObjs.Last(), null).ObjToString();
|
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 });
|
||||||
@@ -499,7 +513,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
DiffLogTableInfo diffTable = new DiffLogTableInfo();
|
DiffLogTableInfo diffTable = new DiffLogTableInfo();
|
||||||
diffTable.TableName = this.EntityInfo.DbTableName;
|
diffTable.TableName = this.EntityInfo.DbTableName;
|
||||||
diffTable.TableDescription = this.EntityInfo.TableDescription;
|
diffTable.TableDescription = this.EntityInfo.TableDescription;
|
||||||
|
@@ -24,6 +24,7 @@ namespace SqlSugar
|
|||||||
public MappingTableList QueryableMappingTableList { get; set; }
|
public MappingTableList QueryableMappingTableList { get; set; }
|
||||||
public Action<T> MapperAction { get; set; }
|
public Action<T> MapperAction { get; set; }
|
||||||
public Action<T, MapperCache<T>> MapperActionWithCache { get; set; }
|
public Action<T, MapperCache<T>> MapperActionWithCache { get; set; }
|
||||||
|
public List<Action<List<T>>> Mappers { get; set; }
|
||||||
public bool IsCache { get; set; }
|
public bool IsCache { get; set; }
|
||||||
public int CacheTime { get; set; }
|
public int CacheTime { get; set; }
|
||||||
public bool IsAs { get; set; }
|
public bool IsAs { get; set; }
|
||||||
@@ -78,7 +79,8 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction) {
|
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction)
|
||||||
|
{
|
||||||
this.MapperAction = mapperAction;
|
this.MapperAction = mapperAction;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -87,6 +89,14 @@ namespace SqlSugar
|
|||||||
this.MapperActionWithCache = mapperAction;
|
this.MapperActionWithCache = mapperAction;
|
||||||
return this;
|
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)
|
public virtual ISugarQueryable<T> AddParameters(object parameters)
|
||||||
{
|
{
|
||||||
@@ -128,6 +138,70 @@ namespace SqlSugar
|
|||||||
});
|
});
|
||||||
return this;
|
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)
|
public virtual ISugarQueryable<T> Where(Expression<Func<T, bool>> expression)
|
||||||
{
|
{
|
||||||
this._Where(expression);
|
this._Where(expression);
|
||||||
@@ -197,7 +271,8 @@ namespace SqlSugar
|
|||||||
Where(SqlBuilder.SqlFalse);
|
Where(SqlBuilder.SqlFalse);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (pkValues.Length == 1&& pkValues.First().GetType().FullName.IsCollectionsList()) {
|
if (pkValues.Length == 1 && pkValues.First().GetType().FullName.IsCollectionsList()|| pkValues.First() is IEnumerable)
|
||||||
|
{
|
||||||
var newValues = new List<object>();
|
var newValues = new List<object>();
|
||||||
foreach (var item in pkValues.First() as IEnumerable)
|
foreach (var item in pkValues.First() as IEnumerable)
|
||||||
{
|
{
|
||||||
@@ -1168,6 +1243,20 @@ namespace SqlSugar
|
|||||||
|
|
||||||
protected void _Mapper<TResult>(List<TResult> result)
|
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)
|
if (this.MapperAction != null)
|
||||||
{
|
{
|
||||||
foreach (TResult item in result)
|
foreach (TResult item in result)
|
||||||
@@ -1176,7 +1265,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.MapperAction((T)Convert.ChangeType(item, typeof(T)));
|
this.MapperAction((T)Convert.ChangeType(item, typeof(T)));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName);
|
Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1192,12 +1282,141 @@ namespace SqlSugar
|
|||||||
this.MapperActionWithCache(item, mapperCache);
|
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);
|
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()
|
protected int GetCount()
|
||||||
{
|
{
|
||||||
var sql = string.Empty;
|
var sql = string.Empty;
|
||||||
@@ -1394,6 +1613,27 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -1781,6 +2021,27 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Aggr
|
#region Aggr
|
||||||
@@ -2028,6 +2289,27 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -2433,6 +2715,29 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -2763,6 +3068,28 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -2819,6 +3146,48 @@ namespace SqlSugar
|
|||||||
_OrderBy(expression, type);
|
_OrderBy(expression, type);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region GroupBy
|
#region GroupBy
|
||||||
@@ -3083,6 +3452,27 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -3186,7 +3576,54 @@ namespace SqlSugar
|
|||||||
_GroupBy(expression);
|
_GroupBy(expression);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Aggr
|
#region Aggr
|
||||||
@@ -3430,6 +3867,27 @@ namespace SqlSugar
|
|||||||
this.Where<T>(whereString, whereObj);
|
this.Where<T>(whereString, whereObj);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -3504,6 +3962,60 @@ namespace SqlSugar
|
|||||||
_OrderBy(expression, type);
|
_OrderBy(expression, type);
|
||||||
return this;
|
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
|
#endregion
|
||||||
|
|
||||||
#region GroupBy
|
#region GroupBy
|
||||||
|
@@ -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 IsAutoRemoveDataCache { get; set; }
|
||||||
public bool IsWithNoLockQuery { 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);
|
ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true);
|
||||||
copyContext.Index = this.Index;
|
copyContext.Index = this.Index;
|
||||||
|
copyContext.InitMappingInfo = this.InitMappingInfo;
|
||||||
|
copyContext.RefreshMapping = this.RefreshMapping;
|
||||||
copyContext.ParameterIndex = this.ParameterIndex;
|
copyContext.ParameterIndex = this.ParameterIndex;
|
||||||
return copyContext;
|
return copyContext;
|
||||||
}
|
}
|
||||||
@@ -134,6 +136,8 @@ namespace SqlSugar
|
|||||||
copyContext.MappingTables = this.MappingTables;
|
copyContext.MappingTables = this.MappingTables;
|
||||||
copyContext.IgnoreComumnList = this.IgnoreComumnList;
|
copyContext.IgnoreComumnList = this.IgnoreComumnList;
|
||||||
copyContext.SqlFuncServices = this.SqlFuncServices;
|
copyContext.SqlFuncServices = this.SqlFuncServices;
|
||||||
|
copyContext.InitMappingInfo = this.InitMappingInfo;
|
||||||
|
copyContext.RefreshMapping = this.RefreshMapping;
|
||||||
return copyContext;
|
return copyContext;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@@ -396,6 +396,9 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
|
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
|
||||||
this.Context.Result.CurrentParameter = null;
|
this.Context.Result.CurrentParameter = null;
|
||||||
|
if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue()) {
|
||||||
|
this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.Type.IsClass())
|
else if (item.Type.IsClass())
|
||||||
|
@@ -254,6 +254,14 @@ namespace SqlSugar
|
|||||||
|
|
||||||
private void ResolveLength(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
|
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;
|
var oldCommonTempDate = parameter.CommonTempData;
|
||||||
parameter.CommonTempData = CommonTempDataType.Result;
|
parameter.CommonTempData = CommonTempDataType.Result;
|
||||||
this.Expression = expression.Expression;
|
this.Expression = expression.Expression;
|
||||||
|
@@ -124,8 +124,9 @@ namespace SqlSugar
|
|||||||
base.Expression = item;
|
base.Expression = item;
|
||||||
base.Start();
|
base.Start();
|
||||||
var subSql = base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString());
|
var subSql = base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString());
|
||||||
if (ResolveExpressType.Update == this.Context.ResolveType) {
|
if (ResolveExpressType.Update == this.Context.ResolveType)
|
||||||
subSql = Regex.Replace(subSql,@" \[\w+?\]\.",this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
{
|
||||||
|
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
||||||
}
|
}
|
||||||
parameter.Context.Result.Append(subSql);
|
parameter.Context.Result.Append(subSql);
|
||||||
});
|
});
|
||||||
|
@@ -47,6 +47,18 @@ namespace SqlSugar
|
|||||||
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
|
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
|
else
|
||||||
{
|
{
|
||||||
Check.Exception(true, "I'm sorry I can't parse the current expression");
|
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 index = item.ConditionalList.IndexOf(con);
|
||||||
var isFirst = index == 0;
|
var isFirst = index == 0;
|
||||||
var isLast = index == (item.ConditionalList.Count - 1);
|
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());
|
builder.AppendFormat(" {0} ( ", con.Key.ToString().ToUpper());
|
||||||
}
|
}
|
||||||
|
@@ -21,11 +21,26 @@ namespace SqlSugar
|
|||||||
ISugarQueryable<T> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
ISugarQueryable<T> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||||
ISugarQueryable<T> Mapper(Action<T> mapperAction);
|
ISugarQueryable<T> Mapper(Action<T> mapperAction);
|
||||||
ISugarQueryable<T> Mapper(Action<T, MapperCache<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(object parameters);
|
||||||
ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
|
ISugarQueryable<T> AddParameters(SugarParameter[] parameters);
|
||||||
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
|
ISugarQueryable<T> AddParameters(List<SugarParameter> parameters);
|
||||||
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left);
|
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(Expression<Func<T, bool>> expression);
|
||||||
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
ISugarQueryable<T> Where(string whereString, object parameters = null);
|
||||||
ISugarQueryable<T> Where(List<IConditionalModel> conditionalModels);
|
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> Where(string whereString, object whereObj = null);
|
||||||
new ISugarQueryable<T, T2> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#region Select
|
||||||
@@ -210,6 +237,19 @@ namespace SqlSugar
|
|||||||
|
|
||||||
new ISugarQueryable<T, T2, T3> Where(string whereString, object parameters = null);
|
new ISugarQueryable<T, T2, T3> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3, T4> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3, T4, T5> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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, 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, 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);
|
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
|
#endregion
|
||||||
|
|
||||||
#region GroupBy
|
#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> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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, 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, 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);
|
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
|
#endregion
|
||||||
|
|
||||||
#region GroupBy
|
#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> Where(string whereString, object parameters = null);
|
||||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> WhereIF(bool isWhere, 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
|
#endregion
|
||||||
|
|
||||||
#region Select
|
#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, 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, 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);
|
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
|
#endregion
|
||||||
|
|
||||||
#region GroupBy
|
#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)
|
public override object FormatValue(object value)
|
||||||
{
|
{
|
||||||
|
var n = "N";
|
||||||
|
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||||
|
{
|
||||||
|
n = "";
|
||||||
|
}
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
return "NULL";
|
return "NULL";
|
||||||
@@ -58,11 +63,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||||
{
|
{
|
||||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return "N'" + GetString(value) + "'";
|
return n+"'" + GetString(value) + "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -90,6 +90,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public override object FormatValue(object value)
|
public override object FormatValue(object value)
|
||||||
{
|
{
|
||||||
|
var n = "N";
|
||||||
|
if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar)
|
||||||
|
{
|
||||||
|
n = "";
|
||||||
|
}
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
return "NULL";
|
return "NULL";
|
||||||
@@ -121,11 +126,11 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
|
||||||
{
|
{
|
||||||
return "N'" + GetString(value).ToSqlFilter() + "'";
|
return n+"'" + GetString(value).ToSqlFilter() + "'";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return "N'" + GetString(value) + "'";
|
return n+"'" + GetString(value) + "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,21 +9,83 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public override void ExistLogic(EntityInfo entityInfo)
|
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())
|
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);
|
this.Context.DbMaintenance.AddColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
|
||||||
columns.Add(dbColumnInfo);
|
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)
|
public override void NoExistLogic(EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
|
@@ -47,7 +47,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
return "ALTER TABLE {0} ADD COLUMN {1} {2}{3}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override string AlterColumnToTableSql
|
protected override string AlterColumnToTableSql
|
||||||
|
@@ -561,6 +561,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
#endregion
|
#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
|
#region DbFirst
|
||||||
public virtual IDbFirst DbFirst
|
public virtual IDbFirst DbFirst
|
||||||
{
|
{
|
||||||
|
@@ -8,6 +8,15 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
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