Files
SqlSugar/SqlServerTest/Demos/5_CodeFirst.cs
sunkaixuan 4f8aa12745 Code First
2017-06-17 19:28:30 +08:00

32 lines
810 B
C#

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class CodeTable
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(Length=40)]
public string Name { get; set; }
}
public class CodeFirst : DemoBase
{
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
db.CodeFirst.InitTables(typeof(CodeTable));
}
}
}