ASP.NET Core Scaffolding Bug for separated projects

A quick fix for ASP.NET Core Scaffolding Bug for separated DbContext & Model.

A quick fix for ASP.NET Core Scaffolding Bug for separated DbContext & Model.


Project structure:

โ”œโ”€โ”€ Solution
โ”‚   โ””โ”€โ”€ BL
โ”‚   โ”‚   โ”œโ”€โ”€ Database
โ”‚   โ”‚   โ””โ”€โ”€ DbContext
โ”‚   โ””โ”€โ”€Core
โ”‚   โ”‚   โ””โ”€โ”€ Models
โ”‚   โ”‚       โ”œโ”€โ”€ApplicationInfo
โ”‚   โ”‚       โ”œโ”€โ”€ VersionInfo
โ”‚   โ”‚       โ””โ”€โ”€ ApplicationInfo
โ”‚   โ””โ”€โ”€ WebApp
โ”‚   โ”‚   โ””โ”€โ”€ Controllers
โ”‚   โ”‚       โ””โ”€โ”€ ApplicationInfoesController
โ”‚ โ€ฆ

When DbContext and Models are placed in separated projects from the main WebApplication, like the one above, Scaffolding will prompt the following error:

Scaffolding error

This issue is being addressed and the patch is releasing soon (hopefully) in Scaffolding v2.0.3.

Meanwhile, a quick fix is to supply full qualifier name into DbSet:

// This will not work

public DbSet<VersionInfo> VersionInfos { get; set; }

// Full model qualifiers must be used in order for Scaffolding to succeed

public DbSet<Core.Models.DbModels.ApplicationInfo> ApplicationInfos { get; set; }