Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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>
like image 914
eldios1981 Avatar asked May 10 '17 12:05

eldios1981


People also ask

What is scaffold-DbContext command?

The above Scaffold-DbContext command creates entity classes for each table in the SchoolDB database and context class (by deriving DbContext ) with Fluent API configurations for all the entities in the Models folder. The following is the generated Student entity class for the Student table.


2 Answers

This worked for me

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 !

like image 129
bereket gebredingle Avatar answered Sep 28 '22 01:09

bereket gebredingle


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/

like image 22
Umer Javaid Avatar answered Sep 27 '22 23:09

Umer Javaid