mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-01-19 17:51:36 +08:00
Update Core
This commit is contained in:
@@ -312,6 +312,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
CommandType = CommandType.Text;
|
||||||
if (ErrorEvent != null)
|
if (ErrorEvent != null)
|
||||||
ExecuteErrorEvent(sql, parameters, ex);
|
ExecuteErrorEvent(sql, parameters, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
@@ -346,6 +347,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
CommandType = CommandType.Text;
|
||||||
if (ErrorEvent != null)
|
if (ErrorEvent != null)
|
||||||
ExecuteErrorEvent(sql, parameters, ex);
|
ExecuteErrorEvent(sql, parameters, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
@@ -375,6 +377,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
CommandType = CommandType.Text;
|
||||||
if (ErrorEvent != null)
|
if (ErrorEvent != null)
|
||||||
ExecuteErrorEvent(sql, parameters, ex);
|
ExecuteErrorEvent(sql, parameters, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
@@ -403,6 +406,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
CommandType = CommandType.Text;
|
||||||
if (ErrorEvent != null)
|
if (ErrorEvent != null)
|
||||||
ExecuteErrorEvent(sql, parameters, ex);
|
ExecuteErrorEvent(sql, parameters, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
@@ -434,6 +438,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
CommandType = CommandType.Text;
|
||||||
if (ErrorEvent != null)
|
if (ErrorEvent != null)
|
||||||
ExecuteErrorEvent(sql,parameters,ex);
|
ExecuteErrorEvent(sql,parameters,ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ICodeFirst SetStringDefaultLength(int length) {
|
public virtual ICodeFirst SetStringDefaultLength(int length)
|
||||||
|
{
|
||||||
DefultLength = length;
|
DefultLength = length;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,23 @@ namespace SqlSugar
|
|||||||
});
|
});
|
||||||
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
||||||
}
|
}
|
||||||
public virtual void InitTables(Type[] entityTypes)
|
public void InitTables<T>()
|
||||||
|
{
|
||||||
|
InitTables(typeof(T));
|
||||||
|
}
|
||||||
|
public void InitTables<T, T2>()
|
||||||
|
{
|
||||||
|
InitTables(typeof(T),typeof(T2));
|
||||||
|
}
|
||||||
|
public void InitTables<T, T2, T3>()
|
||||||
|
{
|
||||||
|
InitTables(typeof(T), typeof(T2),typeof(T3));
|
||||||
|
}
|
||||||
|
public void InitTables<T, T2, T3, T4>()
|
||||||
|
{
|
||||||
|
InitTables(typeof(T), typeof(T2), typeof(T3),typeof(T4));
|
||||||
|
}
|
||||||
|
public virtual void InitTables(params Type[] entityTypes)
|
||||||
{
|
{
|
||||||
if (entityTypes.HasValue())
|
if (entityTypes.HasValue())
|
||||||
{
|
{
|
||||||
@@ -74,10 +91,12 @@ namespace SqlSugar
|
|||||||
protected virtual void Execute(Type entityType)
|
protected virtual void Execute(Type entityType)
|
||||||
{
|
{
|
||||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
||||||
if (this.DefultLength > 0) {
|
if (this.DefultLength > 0)
|
||||||
|
{
|
||||||
foreach (var item in entityInfo.Columns)
|
foreach (var item in entityInfo.Columns)
|
||||||
{
|
{
|
||||||
if (item.PropertyInfo.PropertyType == UtilConstants.StringType && item.DataType.IsNullOrEmpty()&& item.Length==0) {
|
if (item.PropertyInfo.PropertyType == UtilConstants.StringType && item.DataType.IsNullOrEmpty() && item.Length == 0)
|
||||||
|
{
|
||||||
item.Length = DefultLength;
|
item.Length = DefultLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,10 +203,12 @@ namespace SqlSugar
|
|||||||
ChangeKey(entityInfo, tableName, item);
|
ChangeKey(entityInfo, tableName, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isMultiplePrimaryKey) {
|
if (isMultiplePrimaryKey)
|
||||||
|
{
|
||||||
var oldPkNames = dbColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
var oldPkNames = dbColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
||||||
var newPkNames = entityColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
var newPkNames = entityColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
||||||
if (!Enumerable.SequenceEqual(oldPkNames,newPkNames)) {
|
if (!Enumerable.SequenceEqual(oldPkNames, newPkNames))
|
||||||
|
{
|
||||||
Check.Exception(true, ErrorMessage.GetThrowMessage("Modification of multiple primary key tables is not supported. Delete tables while creating", "不支持修改多主键表,请删除表在创建"));
|
Check.Exception(true, ErrorMessage.GetThrowMessage("Modification of multiple primary key tables is not supported. Delete tables while creating", "不支持修改多主键表,请删除表在创建"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,14 @@ namespace SqlSugar
|
|||||||
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||||
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
||||||
}
|
}
|
||||||
|
resolveExpress.InitMappingInfo = Context.InitMppingInfo;
|
||||||
|
resolveExpress.RefreshMapping = () =>
|
||||||
|
{
|
||||||
|
resolveExpress.MappingColumns = Context.MappingColumns;
|
||||||
|
resolveExpress.MappingTables = Context.MappingTables;
|
||||||
|
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||||
|
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
||||||
|
};
|
||||||
resolveExpress.Resolve(expression, resolveType);
|
resolveExpress.Resolve(expression, resolveType);
|
||||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||||
var result = resolveExpress.Result;
|
var result = resolveExpress.Result;
|
||||||
|
|||||||
@@ -162,7 +162,15 @@ namespace SqlSugar
|
|||||||
else if (isMapping)
|
else if (isMapping)
|
||||||
{
|
{
|
||||||
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
|
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
|
||||||
return SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.DbTableName) + SqlTranslationRight;
|
var name = (mappingInfo == null ? entityName : mappingInfo.DbTableName);
|
||||||
|
if (name.Contains("."))
|
||||||
|
{
|
||||||
|
return string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SqlTranslationLeft + name + SqlTranslationRight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (isComplex)
|
else if (isComplex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,9 +124,20 @@ 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 (subSql.Contains(",")) {
|
||||||
|
subSql = subSql.Replace(",", UtilConstants.ReplaceCommaKey);
|
||||||
|
}
|
||||||
if (ResolveExpressType.Update == this.Context.ResolveType)
|
if (ResolveExpressType.Update == this.Context.ResolveType)
|
||||||
{
|
{
|
||||||
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
string name = this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name, true);
|
||||||
|
if (name.Contains("."))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", name + ".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parameter.Context.Result.Append(subSql);
|
parameter.Context.Result.Append(subSql);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
if (type.IsAnonymousType()||type==UtilConstants.ObjType|| type.Namespace=="SqlSugar"|| type.IsClass()==false)
|
||||||
|
{
|
||||||
|
return base.CreateProperties(type, memberSerialization);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var list = type.GetProperties()
|
var list = type.GetProperties()
|
||||||
.Where(x => !x.GetCustomAttributes(true).Any(a => (a is SugarColumn) && ((SugarColumn)a).NoSerialize == true))
|
.Where(x => !x.GetCustomAttributes(true).Any(a => (a is SugarColumn) && ((SugarColumn)a).NoSerialize == true))
|
||||||
@@ -54,6 +60,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void CreateDateProperty(Type type, JsonProperty item)
|
private static void CreateDateProperty(Type type, JsonProperty item)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ namespace SqlSugar
|
|||||||
void InitTables(string[] entitiesNamespaces);
|
void InitTables(string[] entitiesNamespaces);
|
||||||
void InitTables(params Type[] entityTypes);
|
void InitTables(params Type[] entityTypes);
|
||||||
void InitTables(Type entityType);
|
void InitTables(Type entityType);
|
||||||
|
void InitTables<T>();
|
||||||
|
void InitTables<T, T2>();
|
||||||
|
void InitTables<T, T2, T3>();
|
||||||
|
void InitTables<T, T2, T3, T4>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user