SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

8 years ago
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class DbFirst : DemoBase
{
public static void Init()
{
var db = GetInstance();
//Create all class
8 years ago
db.DbFirst.CreateClassFile("c:\\DemoMySql\\1");
8 years ago
//Create student calsss
8 years ago
db.DbFirst.Where("Student").CreateClassFile("c:\\DemoMySql\\2");
8 years ago
//Where(array)
//Mapping name
db.MappingTables.Add("ClassStudent", "Student");
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
8 years ago
db.DbFirst.Where("Student").CreateClassFile("c:\\DemoMySql\\3");
8 years ago
//Remove mapping
db.MappingTables.Clear();
//Create class with default value
8 years ago
db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\DemoMySql\\4", "Demo.Models");
8 years ago
//Mapping and Attribute
db.MappingTables.Add("ClassStudent", "Student");
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
8 years ago
db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\DemoMySql\\5");
8 years ago
//Remove mapping
db.MappingTables.Clear();
db.MappingColumns.Clear();
//Custom format,Change old to new
db.DbFirst.
SettingClassTemplate(old =>
{
return old;
})
.SettingNamespaceTemplate(old =>
{
return old;
})
.SettingPropertyDescriptionTemplate(old =>
{
return @" /// <summary>
/// Desc_New:{PropertyDescription}
/// Default_New:{DefaultValue}
/// Nullable_New:{IsNullable}
/// </summary>";
})
.SettingPropertyTemplate(old =>
{
return old;
})
.SettingConstructorTemplate(old =>
{
return old;
})
8 years ago
.CreateClassFile("c:\\DemoMySql\\6");
8 years ago
}
}
}