mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update db.first
This commit is contained in:
parent
391fb59fb5
commit
216b6adee6
@ -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
|
||||
|
@ -21,7 +21,8 @@ namespace SqlSugar
|
||||
private bool IsDefaultValue { get; set; }
|
||||
private Func<string, bool> WhereColumnsfunc;
|
||||
private Func<string, string> FormatFileNameFunc { get; set; }
|
||||
private bool IsStringNullable {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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user