-
Notifications
You must be signed in to change notification settings - Fork 1.3k
0.1 DbFirst
果糖网 edited this page Jun 23, 2024
·
10 revisions
Generate entity file
//.net framework
db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\1", "Models");
//.net6+ string?
db.DbFirst.IsCreateAttribute().StringNullable().CreateClassFile("c:\\Demo\\1", "Models");
db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\Demo\\2", "Models");
db.DbFirst.IsCreateAttribute().Where(it => it.ToLower().StartsWith("view")).CreateClassFile("c:\\Demo\\3", "Models");
db.DbFirst.IsCreateAttribute().Where(it => it.ToLower().StartsWith("view")).CreateClassFile("c:\\Demo\\4", "Models");
db.DbFirst.IsCreateAttribute().IsCreateDefaultValue().CreateClassFile("c:\\Demo\\6", "Demo.Models");
db.DbFirst.Where("Student")
.IsCreateAttribute()
.CreatedReplaceClassString(it = > it. Replace (" XXX, "" yyy")) / / can also use regular Regex. Replace
.CreateClassFile("c:\\Demo\\2", "Models");
Add a SettingPropertyTemplate overload to strengthen the definition of custom properties
db.DbFirst
// class
.SettingClassTemplate(old => { return old; /* Modify old value Replace */})
// Class constructor
.SettingConstructorTemplate(old =>{return old; /* Modify old value Replace */})
.SettingNamespaceTemplate(old => {
return old + "\r\nusing SqlSugar;" ; // Append references to SqlSugar
})
// Property Remarks
.SettingPropertyDescriptionTemplate(old =>{ return old; /* Modify old value Replace */})
// Properties: New overload fully custom configuration
.SettingPropertyTemplate((columns,temp,type) => {
var columnattribute = "\r\n [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\\7");
Note: This feature may conflict with IsCreateAttribute. Do not use it together
- Format the class name and attribute name
db.DbFirst
.IsCreateAttribute()// Create sqlsugar features
.FormatFileName(it => "File_" + it) // formatfilename (file name is different from table name)
.FormatClassName(it => "Class_" + it)// Formatting the class name (if the class name is different from the table name)
.FormatPropertyName(it => "Property_" + it)// Formatting property name (property name and field name is different)
.CreateClassFile("c:\\Demo\\4", "Models");
This replacement consumes the most performance and can be replaced with other functions before other functions
//replacement strings
db.DbFirst.Where("Student")
CreatedReplaceClassString (it = > it. Replace (" XXX, "" yyy")) / / can also use regular Regex. Replace
.CreateClassFile("c:\\Demo\\2", "Models");
db.DbFirst.Where("order").SettingClassDescriptionTemplate(it => {
return it+"\r\n [Tenant(\""+db.CurrentConnectionConfig.ConfigId+"\")]";
}).CreateClassFile("c:\\Demo\\1", "Models");
9. Generate a String? .NET 7+
db.DbFirst.StringNullable().CreateClassFile("c\\"); // Can the null type string be added?