mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-03 20:27:56 +08:00
Update Core
This commit is contained in:
parent
a020daf9f8
commit
75766b3735
@ -352,7 +352,7 @@ namespace SqlSugar
|
||||
ExecuteBefore(sql, parameters);
|
||||
IDbCommand sqlCommand = GetCommand(sql, parameters);
|
||||
object scalar = sqlCommand.ExecuteScalar();
|
||||
scalar = (scalar == null ? 0 : scalar);
|
||||
//scalar = (scalar == null ? 0 : scalar);
|
||||
if (this.IsClearParameters)
|
||||
sqlCommand.Parameters.Clear();
|
||||
ExecuteAfter(sql, parameters);
|
||||
@ -730,7 +730,7 @@ namespace SqlSugar
|
||||
|
||||
private void SetConnectionEnd(string sql)
|
||||
{
|
||||
if (this.IsMasterSlaveSeparation && IsRead(sql))
|
||||
if (this.IsMasterSlaveSeparation && IsRead(sql)&&this.Transaction==null)
|
||||
{
|
||||
this.Connection = this.MasterConnection;
|
||||
this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;
|
||||
|
@ -140,7 +140,7 @@ namespace SqlSugar
|
||||
public virtual string GetPropertyTypeName(string dbTypeName)
|
||||
{
|
||||
dbTypeName = dbTypeName.ToLower();
|
||||
var propertyTypes = MappingTypes.Where(it => it.Key.Equals(dbTypeName,StringComparison.CurrentCultureIgnoreCase));
|
||||
var propertyTypes = MappingTypes.Where(it => it.Key.Equals(dbTypeName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (dbTypeName == "int32")
|
||||
{
|
||||
return "int";
|
||||
@ -161,6 +161,10 @@ namespace SqlSugar
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
else if (dbTypeName.IsContainsIn("boolean", "bool"))
|
||||
{
|
||||
return "bool";
|
||||
}
|
||||
else if (propertyTypes == null || propertyTypes.Count() == 0)
|
||||
{
|
||||
Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName));
|
||||
|
@ -28,6 +28,7 @@ namespace SqlSugar
|
||||
string sql = DeleteBuilder.ToSqlString();
|
||||
var paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToArray();
|
||||
RestoreMapping();
|
||||
AutoRemoveDataCache();
|
||||
return Db.ExecuteCommand(sql, paramters);
|
||||
}
|
||||
public bool ExecuteCommandHasChange()
|
||||
@ -270,6 +271,17 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
|
||||
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService != null && extService.DataInfoCacheService != null)
|
||||
{
|
||||
this.RemoveDataCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IDeleteable<T> CopyDeleteable()
|
||||
{
|
||||
var asyncContext = this.Context.Utilities.CopyContext(true);
|
||||
|
@ -32,6 +32,7 @@ namespace SqlSugar
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = false;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
@ -41,6 +42,7 @@ namespace SqlSugar
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, InsertBuilder.Parameters);
|
||||
@ -49,6 +51,7 @@ namespace SqlSugar
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
@ -57,6 +60,7 @@ namespace SqlSugar
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
@ -194,6 +198,15 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
|
||||
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService != null && extService.DataInfoCacheService != null)
|
||||
{
|
||||
this.RemoveDataCache();
|
||||
}
|
||||
}
|
||||
protected virtual void PreToSql()
|
||||
{
|
||||
#region Identities
|
||||
|
@ -439,6 +439,7 @@ namespace SqlSugar
|
||||
{
|
||||
Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Queryable.Select Method .");
|
||||
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList ");
|
||||
ToSqlBefore();
|
||||
var sql = QueryBuilder.ToSqlString();
|
||||
var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable");
|
||||
var mergeQueryable = this.Context.Queryable<ExpandoObject>();
|
||||
@ -607,6 +608,7 @@ namespace SqlSugar
|
||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
{
|
||||
InitMapping();
|
||||
ToSqlBefore();
|
||||
string sql = QueryBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
||||
@ -1059,12 +1061,21 @@ namespace SqlSugar
|
||||
protected int GetCount()
|
||||
{
|
||||
var sql = string.Empty;
|
||||
ToSqlBefore();
|
||||
sql = QueryBuilder.ToSqlString();
|
||||
sql = QueryBuilder.ToCountSql(sql);
|
||||
var reval = Context.Ado.GetInt(sql, QueryBuilder.Parameters.ToArray());
|
||||
return reval;
|
||||
}
|
||||
|
||||
private void ToSqlBefore()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
if (moreSetts != null && moreSetts.IsWithNoLockQuery&&string.IsNullOrEmpty(QueryBuilder.TableWithString)) {
|
||||
this.With(SqlWith.NoLock);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||
{
|
||||
List<TResult> result;
|
||||
@ -1286,6 +1297,24 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2> Having(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2> Having(Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2> Having(string whereString, object whereObj)
|
||||
{
|
||||
base.Having(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
@ -1425,6 +1454,30 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3> Having(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3> Having(Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3> Having(Expression<Func<T, T2, T3, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3> Having(string whereString, object whereObj)
|
||||
{
|
||||
base.Having(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Order
|
||||
@ -1819,6 +1872,35 @@ namespace SqlSugar
|
||||
_GroupBy(expression);
|
||||
return this;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4> Having(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> Having(Expression<Func<T, T2, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> Having(Expression<Func<T, T2, T3, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISugarQueryable<T, T2, T3, T4> Having(Expression<Func<T, T2, T3, T4, bool>> expression)
|
||||
{
|
||||
this._Having(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
public new ISugarQueryable<T, T2, T3, T4> Having(string whereString, object whereObj)
|
||||
{
|
||||
base.Having(whereString, whereObj);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Aggr
|
||||
|
@ -432,7 +432,7 @@ namespace SqlSugar
|
||||
{
|
||||
result += (TableShortName + UtilConstants.Space);
|
||||
}
|
||||
if (this.TableWithString.HasValue())
|
||||
if (this.TableWithString.HasValue()&&this.TableWithString!= SqlWith.Null)
|
||||
{
|
||||
result += TableWithString + UtilConstants.Space;
|
||||
}
|
||||
@ -443,7 +443,7 @@ namespace SqlSugar
|
||||
if (this.EasyJoinInfos.IsValuable())
|
||||
{
|
||||
|
||||
if (this.TableWithString.HasValue())
|
||||
if (this.TableWithString.HasValue() && this.TableWithString != SqlWith.Null)
|
||||
{
|
||||
result += "," + string.Join(",", this.EasyJoinInfos.Select(it => string.Format("{0} {1} {2} ", GetTableName(it.Value), it.Key, TableWithString)));
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ namespace SqlSugar
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
string sql = UpdateBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
@ -93,7 +94,15 @@ namespace SqlSugar
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(leftResultString, resultString));
|
||||
return this;
|
||||
}
|
||||
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
|
||||
if (moreSetts != null && moreSetts.IsAutoRemoveDataCache && extService!=null&& extService.DataInfoCacheService!=null)
|
||||
{
|
||||
this.RemoveDataCache();
|
||||
}
|
||||
}
|
||||
public KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
{
|
||||
PreToSql();
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class ConnMoreSettings
|
||||
{
|
||||
public bool IsAutoRemoveDataCache { get; set; }
|
||||
public bool IsWithNoLockQuery { get; set; }
|
||||
}
|
||||
}
|
@ -39,6 +39,10 @@ namespace SqlSugar
|
||||
/// All operations within a transaction is ConnectionString
|
||||
/// </summary>
|
||||
public List<SlaveConnectionConfig> SlaveConnectionConfigs { get; set; }
|
||||
/// <summary>
|
||||
/// More Gobal Settings
|
||||
/// </summary>
|
||||
public ConnMoreSettings MoreSettings { get; set; }
|
||||
}
|
||||
|
||||
public class ConfigureExternalServices
|
||||
|
@ -15,5 +15,6 @@ namespace SqlSugar
|
||||
public const string TabLockX = "WITH(TABLOCKX)";
|
||||
public const string UpdLock = "WITH(UPDLOCK)";
|
||||
public const string RowLock = "WITH(ROWLOCK)";
|
||||
public const string Null = "Non";
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,11 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in args)
|
||||
{
|
||||
AppendItem(parameter, name, args, model, item);
|
||||
var expItem = item;
|
||||
if (item is UnaryExpression) {
|
||||
expItem = (item as UnaryExpression).Operand;
|
||||
}
|
||||
AppendItem(parameter, name, args, model, expItem);
|
||||
}
|
||||
if (appendArgs != null)
|
||||
{
|
||||
|
@ -137,8 +137,50 @@ namespace SqlSugar
|
||||
var reval = this.Context.EntityMaintenance.GetEntityInfo(type);
|
||||
return reval;
|
||||
});
|
||||
InitMppingInfo(entityInfo);
|
||||
var copyObj = CopyEntityInfo(entityInfo);
|
||||
InitMppingInfo(copyObj);
|
||||
}
|
||||
|
||||
private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
|
||||
{
|
||||
EntityInfo result = new EntityInfo()
|
||||
{
|
||||
DbTableName = entityInfo.DbTableName,
|
||||
EntityName = entityInfo.EntityName,
|
||||
Type = entityInfo.Type
|
||||
};
|
||||
List<EntityColumnInfo> columns = new List<EntityColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
foreach (var item in entityInfo.Columns)
|
||||
{
|
||||
EntityColumnInfo column = new EntityColumnInfo()
|
||||
{
|
||||
ColumnDescription = item.ColumnDescription,
|
||||
DataType = item.DataType,
|
||||
DbColumnName = item.DbColumnName,
|
||||
DbTableName = item.DbTableName,
|
||||
DecimalDigits = item.DecimalDigits,
|
||||
DefaultValue = item.DefaultValue,
|
||||
EntityName = item.EntityName,
|
||||
IsIdentity = item.IsIdentity,
|
||||
IsIgnore = item.IsIgnore,
|
||||
IsNullable = item.IsNullable,
|
||||
IsOnlyIgnoreInsert = item.IsOnlyIgnoreInsert,
|
||||
IsPrimarykey = item.IsPrimarykey,
|
||||
Length = item.Length,
|
||||
OldDbColumnName = item.OldDbColumnName,
|
||||
OracleSequenceName = item.OracleSequenceName,
|
||||
PropertyInfo = item.PropertyInfo,
|
||||
PropertyName = item.PropertyName
|
||||
};
|
||||
columns.Add(item);
|
||||
}
|
||||
}
|
||||
result.Columns = columns;
|
||||
return result;
|
||||
}
|
||||
|
||||
private void InitMppingInfo(EntityInfo entityInfo)
|
||||
{
|
||||
if (this.Context.MappingTables == null)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -376,7 +376,7 @@ namespace SqlSugar
|
||||
}
|
||||
var allSql = sqlBuilder.GetUnionAllSql(allItems.Select(it => it.Key).ToList());
|
||||
var allParameters = allItems.SelectMany(it => it.Value).ToArray();
|
||||
var resulut = base.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable"));
|
||||
var resulut = base.Context.Queryable<ExpandoObject>().AS(UtilMethods.GetPackTable(allSql, "unionTable")).With(SqlWith.Null);
|
||||
resulut.AddParameters(allParameters);
|
||||
return resulut.Select<T>(sqlBuilder.SqlSelectAll);
|
||||
}
|
||||
@ -391,7 +391,7 @@ namespace SqlSugar
|
||||
public ISugarQueryable<T> SqlQueryable<T>(string sql) where T : class, new()
|
||||
{
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(base.Context.CurrentConnectionConfig);
|
||||
return base.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).Select("*");
|
||||
return base.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select("*");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user