mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update Core
This commit is contained in:
parent
54fcde3935
commit
b648c0116f
@ -55,6 +55,7 @@ namespace SqlSugar
|
||||
public virtual Action<string, SugarParameter[]> LogEventStarting { get; set; }
|
||||
public virtual Action<string, SugarParameter[]> LogEventCompleted { get; set; }
|
||||
public virtual Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> ProcessingEventStartingSQL { get; set; }
|
||||
protected virtual Func<string,string> FormatSql { get; set; }
|
||||
public virtual Action<Exception> ErrorEvent { get; set; }
|
||||
public virtual List<IDbConnection> SlaveConnections { get; set; }
|
||||
public virtual IDbConnection MasterConnection { get; set; }
|
||||
@ -254,6 +255,8 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql, parameters);
|
||||
@ -281,6 +284,8 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
SetConnectionStart(sql);
|
||||
var isSp = this.CommandType == CommandType.StoredProcedure;
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
@ -307,6 +312,8 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql, parameters);
|
||||
@ -337,6 +344,8 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql, parameters);
|
||||
|
@ -109,7 +109,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (!ReaderKeys.Contains(mappInfo.DbColumnName))
|
||||
{
|
||||
fileName = ReaderKeys.Single(it => it.Equals(mappInfo.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
fileName = ReaderKeys.First(it => it.Equals(mappInfo.DbColumnName, StringComparison.CurrentCultureIgnoreCase)|| it.Equals(mappInfo.PropertyName, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -137,11 +137,18 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var tableInfo in this.TableInfoList)
|
||||
{
|
||||
string classText = null;
|
||||
string className = tableInfo.Name;
|
||||
classText = GetClassString(tableInfo, ref className);
|
||||
result.Remove(className);
|
||||
result.Add(className, classText);
|
||||
try
|
||||
{
|
||||
string classText = null;
|
||||
string className = tableInfo.Name;
|
||||
classText = GetClassString(tableInfo, ref className);
|
||||
result.Remove(className);
|
||||
result.Add(className, classText);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, "Table '{0}' error,You can filter it with Db.DbFirst.Where(name=>name!=\"{0}\" ) \r\n Error message:{1}", tableInfo.Name, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -135,6 +135,7 @@ namespace SqlSugar
|
||||
column.DataType = sugarColumn.ColumnDataType;
|
||||
column.DecimalDigits = sugarColumn.DecimalDigits;
|
||||
column.OracleSequenceName = sugarColumn.OracleSequenceName;
|
||||
column.IsOnlyIgnoreInsert = sugarColumn.IsOnlyIgnoreInsert;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -219,6 +219,15 @@ namespace SqlSugar
|
||||
return !currentIgnoreColumns.Any(i => it.PropertyName.Equals(i.PropertyName, StringComparison.CurrentCulture));
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
if (this.Context.IgnoreInsertColumns != null && this.Context.IgnoreInsertColumns.Any())
|
||||
{
|
||||
var currentIgnoreColumns = this.Context.IgnoreInsertColumns.Where(it => it.EntityName == this.EntityInfo.EntityName).ToList();
|
||||
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it =>
|
||||
{
|
||||
return !currentIgnoreColumns.Any(i => it.PropertyName.Equals(i.PropertyName, StringComparison.CurrentCulture));
|
||||
}).ToList();
|
||||
}
|
||||
#endregion
|
||||
if (this.IsSingle)
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ namespace SqlSugar
|
||||
item.IsPrimarykey = true;
|
||||
}
|
||||
}
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumns.Any(uc => uc.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey || it.IsIdentity).ToList();
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumns.Any(uc => uc.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase) || uc.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey || it.IsIdentity).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace SqlSugar
|
||||
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
|
||||
Check.Exception(!(binaryExp.Left is MemberExpression), "No support {0}", columns.ToString());
|
||||
Check.Exception(ExpressionTool.IsConstExpression(binaryExp.Left as MemberExpression), "No support {0}", columns.ToString());
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Trim().TrimStart('(').TrimEnd(')');
|
||||
var expResult = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.WhereSingle).GetResultString().Replace("))",") )").Replace("((", "( (").Trim().TrimStart('(').TrimEnd(')');
|
||||
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
||||
|
@ -25,5 +25,6 @@ namespace SqlSugar
|
||||
public string DataType { get; set; }
|
||||
public int DecimalDigits { get; set; }
|
||||
public string OracleSequenceName { get; set; }
|
||||
public bool IsOnlyIgnoreInsert { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,13 @@ namespace SqlSugar
|
||||
get { return _OracleSequenceName; }
|
||||
set { _OracleSequenceName = value; }
|
||||
}
|
||||
|
||||
private bool _IsOnlyIgnoreInsert;
|
||||
public bool IsOnlyIgnoreInsert
|
||||
{
|
||||
get { return _IsOnlyIgnoreInsert; }
|
||||
set { _IsOnlyIgnoreInsert = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace SqlSugar
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public ISugarQueryable<T> CreateMapping<T>() where T : class, new()
|
||||
{
|
||||
Check.ArgumentNullException(Context, "Please use Sqlugar.ModelContext");
|
||||
using (Context)
|
||||
{
|
||||
return Context.Queryable<T>();
|
||||
|
@ -124,6 +124,17 @@ namespace SqlSugar
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
return copyContext;
|
||||
}
|
||||
public ExpressionContext GetCopyContextWithMapping()
|
||||
{
|
||||
ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true);
|
||||
copyContext.Index = this.Index;
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
copyContext.MappingColumns = this.MappingColumns;
|
||||
copyContext.MappingTables = this.MappingTables;
|
||||
copyContext.IgnoreComumnList = this.IgnoreComumnList;
|
||||
copyContext.SqlFuncServices = this.SqlFuncServices;
|
||||
return copyContext;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Override methods
|
||||
|
@ -379,7 +379,7 @@ namespace SqlSugar
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
var newContext = this.Context.GetCopyContext();
|
||||
var newContext = this.Context.GetCopyContextWithMapping();
|
||||
var resolveExpressType = this.Context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
|
||||
newContext.Resolve(item, resolveExpressType);
|
||||
this.Context.Index = newContext.Index;
|
||||
|
@ -49,6 +49,7 @@ namespace SqlSugar
|
||||
public MappingTableList MappingTables = new MappingTableList();
|
||||
public MappingColumnList MappingColumns = new MappingColumnList();
|
||||
public IgnoreColumnList IgnoreColumns = new IgnoreColumnList();
|
||||
public IgnoreColumnList IgnoreInsertColumns = new IgnoreColumnList();
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
@ -146,6 +147,8 @@ namespace SqlSugar
|
||||
this.Context.MappingColumns = new MappingColumnList();
|
||||
if (this.Context.IgnoreColumns == null)
|
||||
this.Context.IgnoreColumns = new IgnoreColumnList();
|
||||
if (this.Context.IgnoreInsertColumns == null)
|
||||
this.Context.IgnoreInsertColumns = new IgnoreColumnList();
|
||||
if (!this.Context.MappingTables.Any(it => it.EntityName == entityInfo.EntityName))
|
||||
{
|
||||
if (entityInfo.DbTableName != entityInfo.EntityName && entityInfo.DbTableName.HasValue())
|
||||
@ -168,6 +171,13 @@ namespace SqlSugar
|
||||
if (!ignoreInfos.Any(it => it.PropertyName == item.PropertyName))
|
||||
this.Context.IgnoreColumns.Add(item.PropertyName, item.EntityName);
|
||||
}
|
||||
|
||||
var ignoreInsertInfos = this.Context.IgnoreInsertColumns.Where(it => it.EntityName == entityInfo.EntityName);
|
||||
foreach (var item in entityInfo.Columns.Where(it => it.IsOnlyIgnoreInsert))
|
||||
{
|
||||
if (!ignoreInsertInfos.Any(it => it.PropertyName == item.PropertyName))
|
||||
this.Context.IgnoreInsertColumns.Add(item.PropertyName, item.EntityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>4.6.0.9</Version>
|
||||
<Version>4.6.1</Version>
|
||||
<Copyright>sun_kai_xuan</Copyright>
|
||||
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
|
||||
<PackageLicenseUrl></PackageLicenseUrl>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>4.6.0.9</version>
|
||||
<version>4.6.1</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user