This commit is contained in:
sunkaixuan
2017-09-29 16:10:02 +08:00
parent fb723127a0
commit 8f7f4bc159

View File

@@ -136,15 +136,28 @@ namespace SqlSugar
{ {
foreach (var tableInfo in this.TableInfoList) 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);
}
}
return result;
}
internal string GetClassString(DbTableInfo tableInfo, ref string className)
{
string classText;
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableInfo.Name); var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableInfo.Name);
if (this.Context.IgnoreColumns.IsValuable()) { if (this.Context.IgnoreColumns.IsValuable())
{
var entityName = this.Context.EntityMaintenance.GetEntityName(tableInfo.Name); var entityName = this.Context.EntityMaintenance.GetEntityName(tableInfo.Name);
columns = columns.Where(c => columns = columns.Where(c =>
!this.Context.IgnoreColumns.Any(ig => ig.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase)&&c.DbColumnName==ig.PropertyName) !this.Context.IgnoreColumns.Any(ig => ig.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase) && c.DbColumnName == ig.PropertyName)
).ToList(); ).ToList();
} }
string className = tableInfo.Name; classText = this.ClassTemplate;
string classText = this.ClassTemplate;
string ConstructorText = IsDefaultValue ? this.ConstructorTemplate : null; string ConstructorText = IsDefaultValue ? this.ConstructorTemplate : null;
if (this.Context.MappingTables.IsValuable()) if (this.Context.MappingTables.IsValuable())
{ {
@@ -177,9 +190,9 @@ namespace SqlSugar
PropertyDescriptionText = GetPropertyDescriptionText(item, PropertyDescriptionText); PropertyDescriptionText = GetPropertyDescriptionText(item, PropertyDescriptionText);
PropertyText = PropertyDescriptionText + PropertyText; PropertyText = PropertyDescriptionText + PropertyText;
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, PropertyText + (isLast ? "" : ("\r\n" + DbFirstTemplate.KeyPropertyName))); classText = classText.Replace(DbFirstTemplate.KeyPropertyName, PropertyText + (isLast ? "" : ("\r\n" + DbFirstTemplate.KeyPropertyName)));
if (ConstructorText.IsValuable() && item.DefaultValue!=null) if (ConstructorText.IsValuable() && item.DefaultValue != null)
{ {
var hasDefaultValue = columns.Skip(index + 1).Any(it=>it.DefaultValue.IsValuable()); var hasDefaultValue = columns.Skip(index + 1).Any(it => it.DefaultValue.IsValuable());
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyPropertyName, propertyName); ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyPropertyName, propertyName);
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyDefaultValue, GetPropertyTypeConvert(item)) + (!hasDefaultValue ? "" : this.ConstructorTemplate); ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyDefaultValue, GetPropertyTypeConvert(item)) + (!hasDefaultValue ? "" : this.ConstructorTemplate);
} }
@@ -191,12 +204,9 @@ namespace SqlSugar
} }
classText = classText.Replace(DbFirstTemplate.KeyConstructor, ConstructorText); classText = classText.Replace(DbFirstTemplate.KeyConstructor, ConstructorText);
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, null); classText = classText.Replace(DbFirstTemplate.KeyPropertyName, null);
result.Remove(className); return classText;
result.Add(className, classText);
}
}
return result;
} }
public void CreateClassFile(string directoryPath, string nameSpace = "Models") public void CreateClassFile(string directoryPath, string nameSpace = "Models")
{ {
Check.ArgumentNullException(directoryPath, "directoryPath can't null"); Check.ArgumentNullException(directoryPath, "directoryPath can't null");