mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Update Core
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugar</id>
|
||||
<version>5.0.0.4</version>
|
||||
<version>5.0.0.5</version>
|
||||
<title>SqlSugar 5.0+ .Net Framework 4.5+ , SqlSugar 4.0+ .Net Framework 4.0+</title>
|
||||
<authors>sun kaixuan</authors>
|
||||
<owners>landa</owners>
|
||||
|
@@ -452,7 +452,7 @@ namespace SqlSugar
|
||||
}
|
||||
protected virtual string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
|
||||
{
|
||||
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
|
||||
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
string dataSize = GetSize(columnInfo);
|
||||
string dataType = columnInfo.DataType;
|
||||
|
@@ -173,6 +173,7 @@ namespace SqlSugar
|
||||
column.NoSerialize = sugarColumn.NoSerialize;
|
||||
column.DefaultValue = sugarColumn.DefaultValue;
|
||||
column.IndexGroupNameList = sugarColumn.IndexGroupNameList;
|
||||
column.IsOnlyIgnoreUpdate = sugarColumn.IsOnlyIgnoreUpdate;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -211,6 +211,7 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
public IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) {
|
||||
Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
|
||||
this.IsOffIdentity = isOffIdentity;
|
||||
if (this.InsertBuilder.LambdaExpressions == null)
|
||||
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
||||
|
@@ -50,6 +50,20 @@ namespace SqlSugar
|
||||
{
|
||||
QueryBuilder.Clear();
|
||||
}
|
||||
public ISugarQueryable<T> IgnoreColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
var ignoreColumns = QueryBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it).ToLower()).ToList();
|
||||
return IgnoreColumns(ignoreColumns.ToArray());
|
||||
}
|
||||
public ISugarQueryable<T> IgnoreColumns(params string[] columns)
|
||||
{
|
||||
if (QueryBuilder.IgnoreColumns.IsNullOrEmpty())
|
||||
{
|
||||
QueryBuilder.IgnoreColumns = new List<string>();
|
||||
}
|
||||
QueryBuilder.IgnoreColumns.AddRange(columns);
|
||||
return this;
|
||||
}
|
||||
public void AddQueue()
|
||||
{
|
||||
var sqlObj = this.ToSql();
|
||||
@@ -824,6 +838,13 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
#region Async methods
|
||||
public virtual async Task<T> InSingleAsync(object pkValue)
|
||||
{
|
||||
Check.Exception(this.QueryBuilder.SelectValue.HasValue(), "'InSingle' and' Select' can't be used together,You can use .Select(it=>...).Single(it.id==1)");
|
||||
var list =await In(pkValue).ToListAsync();
|
||||
if (list == null) return default(T);
|
||||
else return list.SingleOrDefault();
|
||||
}
|
||||
public async Task<T> SingleAsync()
|
||||
{
|
||||
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
|
||||
@@ -1878,6 +1899,7 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex;
|
||||
asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos;
|
||||
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
|
||||
asyncQueryableBuilder.IgnoreColumns = this.QueryBuilder.IgnoreColumns;
|
||||
}
|
||||
protected int SetCacheTime(int cacheDurationInSeconds)
|
||||
{
|
||||
|
@@ -33,6 +33,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Splicing basic
|
||||
public List<string> IgnoreColumns { get; set; }
|
||||
public bool IsCount { get; set; }
|
||||
public int? Skip { get; set; }
|
||||
public int ExternalPageIndex { get; set; }
|
||||
@@ -429,7 +430,12 @@ namespace SqlSugar
|
||||
{
|
||||
pre = Builder.GetTranslationColumnName(TableShortName) + ".";
|
||||
}
|
||||
result = string.Join(",", this.Context.EntityMaintenance.GetEntityInfo(this.EntityType).Columns.Where(it => !it.IsIgnore).Select(it => pre + Builder.GetTranslationColumnName(it.EntityName, it.PropertyName)));
|
||||
var columns = this.Context.EntityMaintenance.GetEntityInfo(this.EntityType).Columns.Where(it => !it.IsIgnore);
|
||||
if (this.IgnoreColumns.HasValue())
|
||||
{
|
||||
columns = columns.Where(c => !this.IgnoreColumns.Any(i=>c.PropertyName.Equals(i,StringComparison.CurrentCultureIgnoreCase)||c.DbColumnName.Equals(i,StringComparison.CurrentCultureIgnoreCase))).ToList();
|
||||
}
|
||||
result = string.Join(",", columns.Select(it => pre + Builder.GetTranslationColumnName(it.EntityName, it.PropertyName)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
public ConnectionConfig CurrentConnectionConfig { get; set; }
|
||||
public Dictionary<string, object> TempItems { get { if (_TempItems == null) { _TempItems = new Dictionary<string, object>(); } return _TempItems; } set=>_TempItems=value; }
|
||||
public Dictionary<string, object> TempItems { get { if (_TempItems == null) { _TempItems = new Dictionary<string, object>(); } return _TempItems; } set { _TempItems = value; } }
|
||||
public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } }
|
||||
public Guid ContextID { get; set; }
|
||||
public MappingTableList MappingTables { get; set; }
|
||||
@@ -291,6 +291,11 @@ namespace SqlSugar
|
||||
sqlBuilder.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.CurrentConnectionConfig);
|
||||
sqlBuilder.Context = result.SqlBuilder.UpdateBuilder.Context = this;
|
||||
result.Init();
|
||||
var ignoreColumns = result.EntityInfo.Columns.Where(it => it.IsOnlyIgnoreUpdate).ToList();
|
||||
if (ignoreColumns!=null&&ignoreColumns.Any())
|
||||
{
|
||||
result = (UpdateableProvider<T>)result.IgnoreColumns(ignoreColumns.Select(it=>it.PropertyName).ToArray());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -878,7 +878,7 @@ namespace SqlSugar
|
||||
}
|
||||
this.Queues.Add(sql, parsmeters);
|
||||
}
|
||||
public QueueList Queues { get { if (_Queues == null) { _Queues = new QueueList(); } return _Queues; } set => _Queues = value; }
|
||||
public QueueList Queues { get { if (_Queues == null) { _Queues = new QueueList(); } return _Queues; } set { _Queues = value; } }
|
||||
|
||||
|
||||
|
||||
|
@@ -120,6 +120,7 @@ namespace SqlSugar
|
||||
|
||||
public IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false,bool ignoreAllDefaultValue = false)
|
||||
{
|
||||
Check.Exception(this.UpdateObjs.Count() > 1 && ignoreAllNullColumns, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
|
||||
UpdateBuilder.IsOffIdentity = isOffIdentity;
|
||||
if (this.UpdateBuilder.LambdaExpressions == null)
|
||||
this.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
||||
@@ -138,7 +139,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (columns.HasValue())
|
||||
{
|
||||
var ignoreColumns = columns;
|
||||
var ignoreColumns = columns.Select(it => it.ToLower()).ToList() ;
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Contains(it.PropertyName.ToLower())).ToList();
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Contains(it.DbColumnName.ToLower())).ToList();
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ namespace SqlSugar
|
||||
public int DecimalDigits { get; set; }
|
||||
public string OracleSequenceName { get; set; }
|
||||
public bool IsOnlyIgnoreInsert { get; set; }
|
||||
public bool IsOnlyIgnoreUpdate { get; set; }
|
||||
public bool IsTranscoding { get; set; }
|
||||
public string SerializeDateTimeFormat { get; set; }
|
||||
public bool IsJson { get; set; }
|
||||
|
@@ -112,6 +112,13 @@ namespace SqlSugar
|
||||
set { _IsOnlyIgnoreInsert = value; }
|
||||
}
|
||||
|
||||
private bool _IsOnlyIgnoreUpdate;
|
||||
public bool IsOnlyIgnoreUpdate
|
||||
{
|
||||
get { return _IsOnlyIgnoreUpdate; }
|
||||
set { _IsOnlyIgnoreUpdate = value; }
|
||||
}
|
||||
|
||||
|
||||
private bool _IsEnableUpdateVersionValidation;
|
||||
public bool IsEnableUpdateVersionValidation {
|
||||
|
@@ -491,6 +491,11 @@ namespace SqlSugar
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
}
|
||||
}
|
||||
protected static bool IsConvert(Expression item)
|
||||
{
|
||||
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
|
||||
}
|
||||
|
||||
protected static bool IsNotMember(Expression item)
|
||||
{
|
||||
return item is UnaryExpression &&
|
||||
|
@@ -109,11 +109,21 @@ namespace SqlSugar
|
||||
}
|
||||
else if (IsConst(item))
|
||||
{
|
||||
var oldCommonTempData = parameter.CommonTempData;
|
||||
if (oldCommonTempData == null)
|
||||
{
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
}
|
||||
base.Expression = item;
|
||||
if (IsConvert(item))
|
||||
{
|
||||
base.Expression = (base.Expression as UnaryExpression).Operand;
|
||||
}
|
||||
base.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
parameter.CommonTempData = oldCommonTempData;
|
||||
this.Context.ParameterIndex++;
|
||||
}
|
||||
else if (item is MemberExpression)
|
||||
@@ -163,7 +173,6 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsConst(Expression item)
|
||||
{
|
||||
return item is UnaryExpression || item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant;
|
||||
|
@@ -515,6 +515,14 @@ namespace SqlSugar
|
||||
case "Contains":
|
||||
return this.Context.DbMehtods.Contains(model);
|
||||
case "ContainsArray":
|
||||
if (model.Args[0].MemberValue == null)
|
||||
{
|
||||
var first = this.Context.Parameters.FirstOrDefault(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||
if (first.HasValue())
|
||||
{
|
||||
model.Args[0].MemberValue = first.Value;
|
||||
}
|
||||
}
|
||||
var caResult = this.Context.DbMehtods.ContainsArray(model);
|
||||
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
|
||||
return caResult;
|
||||
|
@@ -54,6 +54,7 @@ namespace SqlSugar
|
||||
ISugarQueryable<T> WhereIF(bool isWhere, string whereString, object parameters = null);
|
||||
|
||||
T InSingle(object pkValue);
|
||||
Task<T> InSingleAsync(object pkValue);
|
||||
ISugarQueryable<T> In<TParamter>(params TParamter[] pkValues);
|
||||
ISugarQueryable<T> In<FieldType>(string InFieldName, params FieldType[] inValues);
|
||||
ISugarQueryable<T> In<FieldType>(Expression<Func<T, object>> expression, params FieldType[] inValues);
|
||||
@@ -151,6 +152,8 @@ namespace SqlSugar
|
||||
string ToClassString(string className);
|
||||
void Clear();
|
||||
void AddQueue();
|
||||
ISugarQueryable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
ISugarQueryable<T> IgnoreColumns(params string[] columns);
|
||||
}
|
||||
public partial interface ISugarQueryable<T, T2> : ISugarQueryable<T>
|
||||
{
|
||||
|
@@ -429,14 +429,20 @@ namespace SqlSugar
|
||||
if (defaultValue.ToLower().IsIn("now()", "current_timestamp"))
|
||||
{
|
||||
string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} default {2}";
|
||||
var dbColumnInfo=this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
else if (defaultValue=="0"|| defaultValue == "1")
|
||||
{
|
||||
string sql = string.Format(AddDefaultValueSql.Replace("'",""), tableName, columnName, defaultValue);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.AddDefaultValue(tableName,columnName,defaultValue);
|
||||
return base.AddDefaultValue(tableName, columnName, defaultValue);
|
||||
}
|
||||
}
|
||||
public override bool IsAnyConstraint(string constraintName)
|
||||
|
@@ -164,13 +164,13 @@ namespace SqlSugar
|
||||
|
||||
protected override string DeleteColumnRemarkSql => "comment on column {1}.{0} is ''";
|
||||
|
||||
protected override string IsAnyColumnRemarkSql => throw new NotSupportedException();
|
||||
protected override string IsAnyColumnRemarkSql { get { throw new NotSupportedException(); } }
|
||||
|
||||
protected override string AddTableRemarkSql => "comment on table {0} is '{1}'";
|
||||
|
||||
protected override string DeleteTableRemarkSql => "comment on table {0} is ''";
|
||||
|
||||
protected override string IsAnyTableRemarkSql => throw new NotSupportedException();
|
||||
protected override string IsAnyTableRemarkSql { get { throw new NotSupportedException(); } }
|
||||
|
||||
protected override string RenameTableSql => "alter table 表名 {0} to {1}";
|
||||
|
||||
|
@@ -67,7 +67,7 @@ namespace SqlSugar
|
||||
.MappingTables
|
||||
.FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));
|
||||
name = (mappingInfo == null ? name : mappingInfo.DbTableName);
|
||||
if (name.Contains("."))
|
||||
if (name.Contains(".")&& !name.Contains("("))
|
||||
{
|
||||
return string.Join(".", name.ToLower().Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight));
|
||||
}
|
||||
@@ -75,9 +75,13 @@ namespace SqlSugar
|
||||
{
|
||||
return name.ToLower();
|
||||
}
|
||||
else if (name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SqlTranslationLeft + name.ToLower() + SqlTranslationRight;
|
||||
return SqlTranslationLeft + name.ToLower().TrimEnd('"').TrimStart('"') + SqlTranslationRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,10 @@ namespace SqlSugar
|
||||
{
|
||||
protected ISqlSugarClient Context { get; set; }
|
||||
|
||||
public ITenant AsTenant()
|
||||
{
|
||||
return this.Context as ITenant;
|
||||
}
|
||||
public ISqlSugarClient AsSugarClient()
|
||||
{
|
||||
return this.Context;
|
||||
@@ -170,7 +174,10 @@ namespace SqlSugar
|
||||
public partial class SimpleClient
|
||||
{
|
||||
protected ISqlSugarClient Context { get; set; }
|
||||
|
||||
public ITenant AsTenant()
|
||||
{
|
||||
return this.Context as ITenant;
|
||||
}
|
||||
public ISqlSugarClient AsSugarClient()
|
||||
{
|
||||
return this.Context;
|
||||
|
@@ -45,17 +45,17 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Global variable
|
||||
public SqlSugarProvider Context { get => GetContext(); }
|
||||
public SqlSugarProvider Context { get { return GetContext(); } }
|
||||
public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig;
|
||||
public ConnectionConfig CurrentConnectionConfig { get => _CurrentConnectionConfig; set => _CurrentConnectionConfig = value; }
|
||||
public Guid ContextID { get => this.Context.ContextID; set => this.Context.ContextID = value; }
|
||||
public ConnectionConfig CurrentConnectionConfig { get { return _CurrentConnectionConfig; } set { _CurrentConnectionConfig = value; } }
|
||||
public Guid ContextID { get { return this.Context.ContextID; } set { this.Context.ContextID = value; } }
|
||||
|
||||
|
||||
public MappingTableList MappingTables { get => _MappingTables; set => _MappingTables = value; }
|
||||
public MappingColumnList MappingColumns { get => _MappingColumns; set => _MappingColumns = value; }
|
||||
public IgnoreColumnList IgnoreColumns { get => _IgnoreColumns; set => _IgnoreColumns = value; }
|
||||
public IgnoreColumnList IgnoreInsertColumns { get => _IgnoreInsertColumns; set => _IgnoreInsertColumns = value; }
|
||||
public Dictionary<string, object> TempItems { get => this.Context.TempItems; set => this.Context.TempItems = value; }
|
||||
public MappingTableList MappingTables { get { return _MappingTables; } set { _MappingTables = value; } }
|
||||
public MappingColumnList MappingColumns { get { return _MappingColumns; } set { _MappingColumns = value; } }
|
||||
public IgnoreColumnList IgnoreColumns { get { return _IgnoreColumns; } set { _IgnoreColumns = value; } }
|
||||
public IgnoreColumnList IgnoreInsertColumns { get { return _IgnoreInsertColumns; } set { _IgnoreInsertColumns = value; } }
|
||||
public Dictionary<string, object> TempItems { get { return this.Context.TempItems; } set { this.Context.TempItems = value; } }
|
||||
#endregion
|
||||
|
||||
#region SimpleClient
|
||||
@@ -340,7 +340,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Queue
|
||||
public QueueList Queues { get => this.Context.Queues; set => this.Context.Queues = value; }
|
||||
public QueueList Queues { get { return this.Context.Queues; } set { this.Context.Queues = value; } }
|
||||
public void AddQueue(string sql, object parsmeters = null)
|
||||
{
|
||||
this.Context.AddQueue(sql, parsmeters);
|
||||
@@ -524,13 +524,13 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region More api
|
||||
public IContextMethods Utilities { get => this.Context.Utilities; set => this.Context.Utilities = value; }
|
||||
public IContextMethods Utilities { get { return this.Context.Utilities; } set { this.Context.Utilities = value; } }
|
||||
public AopProvider Aop => this.Context.Aop;
|
||||
public ICodeFirst CodeFirst => this.Context.CodeFirst;
|
||||
public IDbFirst DbFirst => this.Context.DbFirst;
|
||||
public IDbMaintenance DbMaintenance => this.Context.DbMaintenance;
|
||||
public EntityMaintenance EntityMaintenance { get => this.Context.EntityMaintenance; set => this.Context.EntityMaintenance = value; }
|
||||
public QueryFilterProvider QueryFilter { get => this.Context.QueryFilter; set => this.Context.QueryFilter = value; }
|
||||
public EntityMaintenance EntityMaintenance { get { return this.Context.EntityMaintenance; } set { this.Context.EntityMaintenance = value; } }
|
||||
public QueryFilterProvider QueryFilter { get { return this.Context.QueryFilter; }set { this.Context.QueryFilter = value; } }
|
||||
#endregion
|
||||
|
||||
#region TenantManager
|
||||
@@ -859,11 +859,11 @@ namespace SqlSugar
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use EntityMaintenance")]
|
||||
public EntityMaintenance EntityProvider { get => this.Context.EntityProvider; set => this.Context.EntityProvider = value; }
|
||||
public EntityMaintenance EntityProvider { get { return this.Context.EntityProvider; } set { this.Context.EntityProvider = value; } }
|
||||
[Obsolete("Use Utilities")]
|
||||
public IContextMethods RewritableMethods { get => this.Context.RewritableMethods; set => this.Context.RewritableMethods = value; }
|
||||
public IContextMethods RewritableMethods { get { return this.Context.RewritableMethods; } set { this.Context.RewritableMethods = value; } }
|
||||
[Obsolete("Use GetSimpleClient")]
|
||||
public SimpleClient SimpleClient => this.Context.SimpleClient;
|
||||
public SimpleClient SimpleClient { get { return this.Context.SimpleClient; } }
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user