.Net6 and VsCode CodeFirst开发和迁移使用
------------VsCode开发.net6---------------------------------- 干货如下:
C# Base language support for C# 包含vscode的调试 C# Dev Kit C# Extensions IntelliCode IntelliCode API Usage Examples IntelliCode Completions IntelliCode for C# Dev Kit IntelliCode Insiders NuGet Package Manager GUI vscode-solution-explorer Auto-Using for C# vscode调试时 其他端口需要关闭不占用,点击vscode左侧的虫子按钮即可-运行和调试


调式运行前会自动打开Swagger,截图省略
Vscode CodeFirst 迁移,使用PgSql,code中下面4个nuget包
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13" />
</ItemGroup>
迁移使用到的命令
===========CodeFirst 如下两种方式命令 0:使用命令行工具 dotnet ef migrations add Init --注意这里是多一个migrationss dotnet ef database update 1:使用程序包管理器控制台 Add-Migration Init Update-Database 无法将“dotnet-ef”项识别为 cmdlet、函数、脚本文件或可运行程序的名称,解决方案如下: Net6的dotnet-ef工具环境: dotnet tool install --global dotnet-ef --version 7.0.13 .NetCore3的dotnet-ef工具环境: dotnet tool install --global dotnet-ef --version 3.1.0
2:=========查看执行的sql脚本
# 生成从最后一次迁移到最新迁移的脚本
dotnet ef migrations script
# 如果你想要指定从特定的迁移生成sql脚本,可以这样做:
dotnet ef migrations script AddNewFeature
=========vscode迁移钥使用到的小插件工具 dotnet ef cli全局安装 dotnet tool install --global dotnet-ef 更新EFCore CLI dotnet tool update --global dotnet-ef 卸载EFCore CLI dotnet tool uninstall --global dotnet-ef 验证EFCORE CLI dotnet ef


如有疑问或者错误的地方,请跟帖,本人会第一时间答复以及相互学习,谢谢!个人会不断的上传自己的学习心得!
好了今天就先到这里,下次有时间再更新,如果存在不合理的地方,欢迎大家多多指教留言!!!

浙公网安备 33010602011771号