[英]Scaffold-DbContext: command not found
i try to reverse engnieer my models from an existing database, but the command: Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models
我尝试从现有数据库中反向工程我的模型,但命令:
Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models
Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models
doesn´t work. Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models
不起作用。
I get the error message like in the title.我收到标题中的错误消息。
I installed the Nuget packeges :我安装了 Nuget 包:
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer.Design
and i don´t know why it doesn´t work.( dotnet ef
commands works) I´m sure its a little problem but i can´t find the solution.我不知道为什么它不起作用。(
dotnet ef
命令有效)我确定这是一个小问题,但我找不到解决方案。 Please help me请帮我
My .csproj:我的.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4">
<Version>1.5.0</Version>
</PackageReference>
<PackageReference Include="IdentityServer4.AccessTokenValidation">
<Version>1.2.0</Version>
</PackageReference>
<PackageReference Include="IdentityServer4.AspNetIdentity">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
</ItemGroup>
</Project>
Install Microsoft EntityFrameworkCore tools nuget package in your project by running the following command in Package Manager Console.通过在包管理器控制台中运行以下命令,在项目中安装 Microsoft EntityFrameworkCore 工具 nuget 包。
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.2
This will install the Cmdlets to run Database first approach via Package Manager Console.这将安装 Cmdlet 以通过包管理器控制台运行数据库优先方法。 For details visit https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/
有关详细信息,请访问https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/
use dotnet ef dbcontext scaffold
instead of Scaffold-DbContext
使用
dotnet ef dbcontext scaffold
而不是Scaffold-DbContext
for instance例如
dotnet ef dbcontext scaffold "Host=my_host;Database=my_db;Username=my_user;Password=my_pw" Npgsql.EntityFrameworkCore.PostgreSQL -c ContextName -o OutPutFolder
run dotnet ef dbcontext scaffold -h
to see options u can pass !运行
dotnet ef dbcontext scaffold -h
以查看您可以通过的选项!
Modify the .csproj
file to include the following section:修改
.csproj
文件以包含以下部分:
<ItemGroup>
<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
Version="1.0.0-msbuild3-final" />
</ItemGroup>
This step is only necessary if the .csproj
file wasn't automatically modified to add the entry when the Tools package was installed.仅当安装工具包时未自动修改
.csproj
文件以添加条目时,才需要此步骤。 See https://github.com/aspnet/EntityFramework/issues/7358 .请参阅https://github.com/aspnet/EntityFramework/issues/7358 。
Restore the packages:恢复软件包:
dotnet restore
Now, check your dotnet ef dbcontext scaffold command.现在,检查您的 dotnet ef dbcontext scaffold 命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.