文章正文

.NET9 中使用EFCore脚手架根据数据库生成Entity

加入时间:2025/8/25 16:16:17

选择安装了Microsoft.EntityFrameworkCore.Tools的类库,打开程序包管理器控制台,选择到对应的安装类库的项目,运行下面代码

 

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
  </ItemGroup>

</Project>

我的项目环境,以及安装的类库

假设用户名和密码都是root,不是的话对应修改
dotnet ef dbcontext scaffold "Server=localhost;Port=3306;Database=数据库名;Uid=root;Pwd=root;Convert Zero Datetime=True;" Pomelo.EntityFrameworkCore.MySql --output-dir Models --force

字体大小[ ]

版权所有:有信心——uxinxin 我的个人网站欢迎常来!手机版(新站开启,请多多关照) 豫ICP备12017930号-1
 豫公网安备41910102000493号