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.

69 lines
2.2 KiB

8 years ago
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
[SugarTable("CodeTable", " table CodeTable")]
8 years ago
public class CodeTable
{
8 years ago
[SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true,ColumnDescription ="XXhaha primary key!!")]
8 years ago
public int Id { get; set; }
8 years ago
[SugarColumn(Length = 21,OldColumnName = "Name2")]
public string Name{ get; set; }
public string IsOk { get; set; }
8 years ago
public Guid Guid { get; set; }
[SugarColumn(ColumnDataType ="int")]
8 years ago
public decimal Decimal { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? DateTime { get; set; }
8 years ago
[SugarColumn(IsNullable = true,OldColumnName = "Dob")]
public double? Dob2 { get; set; }
7 years ago
[SugarColumn(Length =11000)]
8 years ago
public string A1 { get; set; }
7 years ago
[SugarColumn(Length = 18,DecimalDigits=2)]
public decimal Dec { get; set; }
8 years ago
}
8 years ago
public class CodeTable2 {
public int Id { get; set; }
public string Name { get; set; }
8 years ago
[SugarColumn(IsIgnore =true)]
public string TestId { get; set; }
8 years ago
}
public class CodeTable3
{
[SugarColumn(IsPrimaryKey =true)]
public int Id { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public string Name { get; set; }
[SugarColumn(IsIgnore = true)]
public string TestId { get; set; }
}
8 years ago
public class CodeFirst : DemoBase
{
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
8 years ago
InitKeyType = InitKeyType.Attribute
8 years ago
});
8 years ago
//Backup table
8 years ago
//db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
8 years ago
//No backup table
db.CodeFirst.SetStringDefaultLength(10).InitTables(typeof(CodeTable),typeof(CodeTable2));
db.CodeFirst.InitTables(typeof(CodeTable3));
8 years ago
}
}
}