1.创建MVC Project 或者空Project。
2.如果是空的Project,请用nuget添加Entity Framework,也可以通过命令行方式添加 Install-Package EntityFramework。
3.修改web.config中的DefaultConnection中的connectionString的对应的数据库
4.在Models目录新建一个继承DbContext的类,类名自己定义,比如AppDbContext,在构造函数中写上数据库链接串的名字
5.新增模型
6.在程序包管理器控制台中输入PM> Add-Migration Init(Init名称自定义,表示一个操作的简单描述)
系统提示:
如果之前已经执行过可以加-Force 参数强制重来
7.在程序包管理器控制台中输入PM>Update-Database 。
系统就会把生成的代码执行到对应的数据库中
8.大功告成!