Update db.first

This commit is contained in:
sunkaixuan 2022-04-21 00:03:33 +08:00
parent 391fb59fb5
commit 216b6adee6
3 changed files with 28 additions and 4 deletions

View File

@ -52,7 +52,23 @@ namespace OrmTest
.SettingConstructorTemplate(old =>{return old; })
.CreateClassFile("c:\\Demo\\7");
db.DbFirst
.SettingPropertyTemplate((columns,temp,type) => {
var columnattribute = "\r [SugarColumn({0})]";
List<string> attributes = new List<string>();
if (columns.IsPrimarykey)
attributes.Add("IsPrimarykey=true");
if (columns.IsIdentity)
attributes.Add("IsIdentity=true");
if (attributes.Count == 0)
{
columnattribute="";
}
return temp.Replace("{PropertyType}", type)
.Replace("{PropertyName}", columns.DbColumnName)
.Replace("{SugarColumn}",string.Format(columnattribute,string.Join(",", attributes)));
})
.CreateClassFile("c:\\Demo\\8");
foreach (var item in db.DbMaintenance.GetTableInfoList())
{
@ -63,7 +79,7 @@ namespace OrmTest
db.MappingColumns.Add(col.DbColumnName.ToUpper() /*Format class property name*/, col.DbColumnName, entityName);
}
}
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\8", "Models");
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\9", "Models");
//Use Razor Template

View File

@ -22,6 +22,7 @@ namespace SqlSugar
private Func<string, bool> WhereColumnsfunc;
private Func<string, string> FormatFileNameFunc { get; set; }
private bool IsStringNullable {get;set; }
private Func<DbColumnInfo,string,string,string> PropertyTextTemplateFunc { get; set; }
private ISqlBuilder SqlBuilder
{
get
@ -97,6 +98,11 @@ namespace SqlSugar
this.PropertyTemplate = func(this.PropertyTemplate);
return this;
}
public IDbFirst SettingPropertyTemplate(Func<DbColumnInfo, string,string,string> func)
{
this.PropertyTextTemplateFunc = func;
return this;
}
public RazorFirst UseRazorAnalysis(string razorClassTemplate, string classNamespace = "Models")
{
if (razorClassTemplate == null)
@ -264,7 +270,7 @@ namespace SqlSugar
string PropertyDescriptionText = this.PropertyDescriptionTemplate;
string propertyName = GetPropertyName(item);
string propertyTypeName = GetPropertyTypeName(item);
PropertyText = GetPropertyText(item, PropertyText);
PropertyText =this.PropertyTextTemplateFunc == null? GetPropertyText(item, PropertyText):this.PropertyTextTemplateFunc(item,this.PropertyTemplate, propertyTypeName);
PropertyDescriptionText = GetPropertyDescriptionText(item, PropertyDescriptionText);
PropertyText = PropertyDescriptionText + PropertyText;
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, PropertyText + (isLast ? "" : ("\r\n" + DbFirstTemplate.KeyPropertyName)));
@ -284,6 +290,7 @@ namespace SqlSugar
classText = classText.Replace(DbFirstTemplate.KeyPropertyName, null);
return classText;
}
internal string GetClassString(List<DbColumnInfo> columns, ref string className)
{
string classText = this.ClassTemplate;

View File

@ -10,6 +10,7 @@ namespace SqlSugar
IDbFirst SettingClassTemplate(Func<string, string> func);
IDbFirst SettingClassDescriptionTemplate(Func<string, string> func);
IDbFirst SettingPropertyTemplate(Func<string, string> func);
IDbFirst SettingPropertyTemplate(Func<DbColumnInfo, string,string,string> func);
IDbFirst SettingPropertyDescriptionTemplate(Func<string, string> func);
IDbFirst SettingConstructorTemplate(Func<string, string> func);
IDbFirst SettingNamespaceTemplate(Func<string, string> func);