.net core 2.0 MVC reference

Personal reference post

https://github.com/davehax/NetCore2_MultiStageForm

All “dotnet xxx” commands need to be run from the command line in the Project Directory

Database-First approach – packages required to scaffold the database into Model classes and then generate Controllers & Views.

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
  <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
  <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
</ItemGroup>

Run

dotnet restore

from the command line install DotNetCliToolReference’s correctly.

 

Some commands to figure things out:

dotnet ef -h
dotnet ef dbcontext -h
dotnet ef dbcontext scaffold -h
dotnet aspnet-codegenerator -h
dotnet aspnet-codegenerator view -h
dotnet aspnet-codegenerator controller -h

 

When running “dotnet aspnet-codegenerator …” and the following error is encountered:

Could not load file or assembly ‘Microsoft.EntityFrameworkCore.Design, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Then the Nuget package titled “Microsoft.EntityFrameworkCore.Design” of the appropriate version must be added to the project.

 

 

After scaffolding a Database you must register the DbContext as a service. The following link will assist:

https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db#register-your-context-with-dependency-injection

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.