• Home
  • About
    • Hanna's Blog photo

      Hanna's Blog

      I wanna be a global developer.

    • Learn More
    • Email
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[Entity Framework Core] Contoso Pets Reverse

25 Jan 2021

Reading time ~1 minute

Reference by Entity Framework Core 101

NuGet Packages

  • Microsoft.EntityFrameworkCore.Design
  • Shared design-time components for Entity Framework Core tools.
Entity Framework Core Contoso Pets

Package Manager Console

  • Scaffold-DbContext
    • Generates code for a DbContext and entity types for a database.
    • In order for Scaffold-DbContext to generate an entity type, the database table must have a primary key.
  Scaffold-DbContext "Data Source=(localdb)\MSSQLLocalDB;initial catalog=ContosoPets;Integrated Security=True;ConnectRetryCount=0" 
  Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context CCIPContext  -DataAnnotations
  • ConnectRetryCount
    • The number of times the driver retries connection attempts to the primary database server, and if specified, alternate servers until a successful connection is established.
    • This option and the Connection Retry Delay connection option, which specifies the wait interval between attempts, can be used in conjunction with failover.
  "ConnectRetryCount=0;"
  • -Provider
    • The provider to use.
    • Typically this is the name of the NuGet package, for example: Microsoft.EntityFrameworkCore.SqlServer.
    • This is a positional parameter and is required.
  Microsoft.EntityFrameworkCore.SqlServer
  • -OutputDir
    • The directory to put files in.
    • Paths are relative to the project directory.
  -OutputDir Models
  • -Context
    • The name of the DbContext class to generate.
  -Context CCIPContext
  • -DataAnnotations
    • Use attributes to configure the model (where possible). If this parameter is omitted, only the fluent API is used.
  -DataAnnotations
Entity Framework Core Contoso Pets Reverse

Result

Entity Framework Core Contoso Pets Reverse

Download



C#DotNetEntity Framework Core Share Tweet +1