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.1 KiB

8 years ago
using SqlSugar;
using System;
8 years ago
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
8 years ago
public class DbFirst : DemoBase
8 years ago
{
public static void Init()
{
8 years ago
var db = GetInstance();
8 years ago
//Create all class
db.DbFirst.CreateClassFile("c:\\Demo\\1");
8 years ago
8 years ago
//Create student calsss
db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\2");
//Where(array)
8 years ago
8 years ago
//Mapping name
db.MappingTables.Add("ClassStudent", "Student");
8 years ago
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
8 years ago
db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\3");
8 years ago
8 years ago
//Remove mapping
db.MappingTables.Clear();
8 years ago
8 years ago
//Create class with default value
8 years ago
db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\Demo\\4", "Demo.Models");
8 years ago
//Mapping and Attribute
db.MappingTables.Add("ClassStudent", "Student");
db.MappingColumns.Add("NewId", "Id", "ClassStudent");
db.DbFirst.IsCreateAttribute().Where("Student").CreateClassFile("c:\\Demo\\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;
})
.CreateClassFile("c:\\Demo\\6");
8 years ago
}
}
}