Code first???????????????
???????????? ???????[ 2016/4/26 11:49:40 ] ?????????????
????1.???
????Code First??Entity Framework????????μ??????????Code First????????????н???????????????????????????????????????????????????????????????????????????????????β??????? ??????г??????????????????β????????β????????????????????????
????2.????????
????2.1????????
/// <summary>
/// model????
/// </summary>
public class model_item : supermodel
{
public model_item()
{
type = ItemType.Normal;//???????????
}
[Required]
[StringLength(16?? MinimumLength = 2)]
public string name { get; set; }
[Required]
[StringLength(16?? MinimumLength = 2)]
public string code { get; set; }
public ItemType type { get; set; }
public bool State { get; set; }
public string Icon { get; set; }
public long sort { get; set; }
public long appid { get; set; }
}
????2.2.DBContext
public class GDG_DbContext : DbContext
{
public GDG_DbContext() : base("GDG_DbContext") { }
public DbSet<model_item> model_item { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
????2.3????????????????
public class DataInit : IDataInitializer<GDG_DbContext>
{
public void Initialize(GDG_DbContext context)
{
List<model_item> fim = new List<model_item>() {
new model_item(){name="?????"??code="gdg"??type= ItemType.Normal??State=true??Icon="taoxin.png"??sort=0??appid=0??reg_time=DateTime.Now}??
new model_item(){name="???"??code="yq"??type= ItemType.Normal??State=true??Icon="juanmao.png"??sort=1??appid=1??reg_time=DateTime.Now}??
new model_item(){name="??????"??code="dys"??type= ItemType.Normal??State=true??Icon="yun.png"??sort=2??appid=2??reg_time=DateTime.Now}??
};
fim.ForEach(o => context.model_item.Add(o));
context.SaveChanges();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11