Search code examples
c#entity-frameworkasp.net-core-scaffolding

How can I create the database entities in a layered application


I have to create a layered .net core application including a database. I want to build the database entities with sql-first approach. The solution looks like this:

Text

All of the projects are class libaries, except the FoodSupplementCompany.Program.

My question is, how can I use Scaffold-DbContext to generate the entities to the FoodSupplementCompany.Data project?


Solution

  • As the guide here states: scaffold-dbcontext

    Example:

    Scaffold-DbContext 
        "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" 
        Microsoft.EntityFrameworkCore.SqlServer
        -OutputDir Models
    

    -OutputDir -> The directory to put files in. Paths are relative to the project directory.