作者:N__Z少爷_763 | 来源:互联网 | 2024-09-24 17:48
其实自动创建数据库的方法和vs for win 的方法并无什么区别,但vs for mac 没有 Nuget CLI(程序包管理器控制台),只能在mac 终端里运行命令
(另:ef的命令工具,调用xxDbcontext时只能调用无参构造函数的context)?待确认
方法
1.一定要添加Microsoft.EntityFrameworkCore,Microsoft.EntityFrameworkCore.Design 两个nuget包
![](https://img1.php1.cn/3cdc5/35ac/1c8/e439d4d71b5a7fd1.jpeg)
2.
找到需要用到的ef的程序集(a)对应的 a.csproj
![](https://img1.php1.cn/3cdc5/35ac/1c8/2e929acdaef136c2.jpeg)
3. 编辑这个csproj ,添加保存以下内容(目前.net core 3.0 及 ef core 3.0可用)
![](https://img1.php1.cn/3cdc5/35ac/1c8/b55b28e1776b83c8.jpeg)
4.打开终端,进入到ef所在的那个程序集的根目录,运行以下命令
dotnet restore
![](https://img1.php1.cn/3cdc5/35ac/1c8/5ab8fdc92f969f3b.jpeg)
5.继续运行命令
dotnet ef migrations add Init
![](https://img1.php1.cn/3cdc5/35ac/1c8/0589dc0366b86ddb.jpeg)
6.运行更新数据库命令 完成!
dotnet ef database update
![](https://img1.php1.cn/3cdc5/35ac/1c8/ff9c8d430a469b92.jpeg)