mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Update Core
This commit is contained in:
@@ -312,6 +312,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
if (ErrorEvent != null)
|
||||
ExecuteErrorEvent(sql, parameters, ex);
|
||||
throw ex;
|
||||
@@ -346,6 +347,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
if (ErrorEvent != null)
|
||||
ExecuteErrorEvent(sql, parameters, ex);
|
||||
throw ex;
|
||||
@@ -375,6 +377,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
if (ErrorEvent != null)
|
||||
ExecuteErrorEvent(sql, parameters, ex);
|
||||
throw ex;
|
||||
@@ -403,6 +406,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
if (ErrorEvent != null)
|
||||
ExecuteErrorEvent(sql, parameters, ex);
|
||||
throw ex;
|
||||
@@ -434,6 +438,7 @@ namespace SqlSugar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
if (ErrorEvent != null)
|
||||
ExecuteErrorEvent(sql,parameters,ex);
|
||||
throw ex;
|
||||
|
@@ -22,7 +22,8 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ICodeFirst SetStringDefaultLength(int length) {
|
||||
public virtual ICodeFirst SetStringDefaultLength(int length)
|
||||
{
|
||||
DefultLength = length;
|
||||
return this;
|
||||
}
|
||||
@@ -43,7 +44,23 @@ namespace SqlSugar
|
||||
});
|
||||
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())
|
||||
{
|
||||
@@ -74,10 +91,12 @@ namespace SqlSugar
|
||||
protected virtual void Execute(Type entityType)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
||||
if (this.DefultLength > 0) {
|
||||
if (this.DefultLength > 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -98,13 +117,13 @@ namespace SqlSugar
|
||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
foreach (var item in entityInfo.Columns.OrderBy(it=>it.IsPrimarykey?0:1).Where(it => it.IsIgnore == false))
|
||||
foreach (var item in entityInfo.Columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).Where(it => it.IsIgnore == false))
|
||||
{
|
||||
DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||
columns.Add(dbColumnInfo);
|
||||
}
|
||||
}
|
||||
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
|
||||
this.Context.DbMaintenance.CreateTable(tableName, columns, true);
|
||||
}
|
||||
public virtual void ExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
@@ -136,7 +155,7 @@ namespace SqlSugar
|
||||
.ToList();
|
||||
|
||||
|
||||
var isMultiplePrimaryKey = dbColumns.Where(it => it.IsPrimarykey).Count() > 1|| entityColumns.Where(it => it.IsPrimarykey).Count() > 1;
|
||||
var isMultiplePrimaryKey = dbColumns.Where(it => it.IsPrimarykey).Count() > 1 || entityColumns.Where(it => it.IsPrimarykey).Count() > 1;
|
||||
|
||||
|
||||
var isChange = false;
|
||||
@@ -167,7 +186,7 @@ namespace SqlSugar
|
||||
if (dbColumn == null) continue;
|
||||
bool pkDiff, idEntityDiff;
|
||||
KeyAction(item, dbColumn, out pkDiff, out idEntityDiff);
|
||||
if (dbColumn != null && pkDiff && !idEntityDiff&& isMultiplePrimaryKey==false)
|
||||
if (dbColumn != null && pkDiff && !idEntityDiff && isMultiplePrimaryKey == false)
|
||||
{
|
||||
var isAdd = item.IsPrimarykey;
|
||||
if (isAdd)
|
||||
@@ -179,15 +198,17 @@ namespace SqlSugar
|
||||
this.Context.DbMaintenance.DropConstraint(tableName, string.Format("PK_{0}_{1}", tableName, item.DbColumnName));
|
||||
}
|
||||
}
|
||||
else if ((pkDiff || idEntityDiff)&& isMultiplePrimaryKey==false)
|
||||
else if ((pkDiff || idEntityDiff) && isMultiplePrimaryKey == false)
|
||||
{
|
||||
ChangeKey(entityInfo, tableName, item);
|
||||
}
|
||||
}
|
||||
if (isMultiplePrimaryKey) {
|
||||
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();
|
||||
if (!Enumerable.SequenceEqual(oldPkNames,newPkNames)) {
|
||||
if (isMultiplePrimaryKey)
|
||||
{
|
||||
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();
|
||||
if (!Enumerable.SequenceEqual(oldPkNames, newPkNames))
|
||||
{
|
||||
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.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);
|
||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||
var result = resolveExpress.Result;
|
||||
|
@@ -162,7 +162,15 @@ namespace SqlSugar
|
||||
else if (isMapping)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@@ -124,9 +124,20 @@ namespace SqlSugar
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
var subSql = base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString());
|
||||
if (subSql.Contains(",")) {
|
||||
subSql = subSql.Replace(",", UtilConstants.ReplaceCommaKey);
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
@@ -50,7 +50,7 @@ namespace SqlSugar
|
||||
this.Context.InitMappingInfo(entityType);
|
||||
this.Context.RefreshMapping();
|
||||
}
|
||||
var result= "FROM "+this.Context.GetTranslationTableName(name, true);
|
||||
var result= "FROM "+this.Context.GetTranslationTableName(name,true);
|
||||
if (this.Context.SubQueryIndex > 0) {
|
||||
result += " subTableIndex"+this.Context.SubQueryIndex;
|
||||
}
|
||||
|
@@ -34,6 +34,12 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
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()
|
||||
.Where(x => !x.GetCustomAttributes(true).Any(a => (a is SugarColumn) && ((SugarColumn)a).NoSerialize == true))
|
||||
@@ -54,6 +60,7 @@ namespace SqlSugar
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateDateProperty(Type type, JsonProperty item)
|
||||
{
|
||||
|
@@ -7,11 +7,15 @@ namespace SqlSugar
|
||||
public partial interface ICodeFirst
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
ICodeFirst BackupTable(int maxBackupDataRows=int.MaxValue);
|
||||
ICodeFirst BackupTable(int maxBackupDataRows = int.MaxValue);
|
||||
ICodeFirst SetStringDefaultLength(int length);
|
||||
void InitTables(string entitiesNamespace);
|
||||
void InitTables(string [] entitiesNamespaces);
|
||||
void InitTables(params Type [] entityTypes);
|
||||
void InitTables(string[] entitiesNamespaces);
|
||||
void InitTables(params Type[] entityTypes);
|
||||
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