您的位置:首页 > 数据库

EntityFramework系列:SQLite.CodeFirst自动生成数据库

2015-04-22 14:50 519 查看
在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。

public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
using (var db = new SqliteDbContext())
{
}
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}


View Code

查看生成的数据库:表映射、关系映射和索引都正确创建了。



调用一下:



代码已经上传到gitosc:http://git.oschina.net/myshare/SQLiteCodeFirst
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: