Reputation: 519
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
doesn´t work.
I get the error message like in the title.
I installed the Nuget packeges :
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. Please help me
My .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>
Upvotes: 9
Views: 20778
Reputation: 220
Install Microsoft EntityFrameworkCore tools nuget package in your project by running the following command in Package Manager Console.
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.2
This will install the Cmdlets to run Database first approach via Package Manager Console. For details visit https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/
Upvotes: 8
Reputation: 12996
use dotnet ef dbcontext scaffold
instead of 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 !
Upvotes: 10
Reputation: 19997
Modify the .csproj
file to include the following section:
<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. See https://github.com/aspnet/EntityFramework/issues/7358.
Restore the packages:
dotnet restore
Now, check your dotnet ef dbcontext scaffold command.
Upvotes: 4