你的位置:首页 > 软件开发 > ASP.net > Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库

Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库

发布时间:2015-04-22 15:02:21
在Code First模式下使用SQLite一直存在不能自动生成数据库的问题,使用SQL Server Compact再转换到SQLite的方式(SQL Server Compact/SQLite Toolbox插件)基本不在我的考虑范围内,直接使用SQL Server Comp ...

在Code First模式下使用SQLite一直存在不能自动生成数据库的问题,使用SQL Server Compact再转换到SQLite的方式(SQL Server Compact/SQLite Toolbox插件)基本不在我的考虑范围内,直接使用SQL Server Compact性能又是问题。理论上我们可以自己去实现SQLite的Code Frist支持,但实际上我只是在等待它的出现。期待了一年多,SQLite.CodeFirst真的出现了。

1.首先定义实体:Customer、Role、Category、Post。

Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库
public class BaseEntity  {    public int Id { get; set; }  }  public class Customer : BaseEntity  {    public Customer()    {      this.Roles = new List<Role>();    }    public string UserName { get; set; }    public virtual ICollection<Role> Roles { get; set; }  }  public class Role : BaseEntity  {    public Role()    {      this.Customers = new List<Customer>();    }    public virtual ICollection<Customer> Customers { get; set; }    public string RoleName { get; set; }  }  public class Category : BaseEntity  {    public Category()    {      this.Children = new List<Category>();      this.Posts = new List<Post>();    }    public int? ParentId { get; set; }    public virtual Category Parent { get; set; }    public virtual ICollection<Category> Children { get; set; }    public virtual ICollection<Post> Posts { get; set; }  }  public class Post : BaseEntity  {    public virtual Category Category { get; set; }  }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库

关键词:sql

sql
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。