Skip to content

Clean Architecture Project Using AdventureWorks2022 DB

Notifications You must be signed in to change notification settings

stacklast/AdventureWorks

Repository files navigation

AdventureWorks

This directory contains the source code for AdventureWorks API.

📃Download the source code

  1. Clone the repository or download the project files:

    git clone <repository-url>

  1. Using SQL Server Restore a DB locally or Using Azure SQL Databases


  1. Change the ConnectionStrings into AdventureWorks.API/appsettings.json

  1. Run Entity Framework Migrations

    • You can run AdventureWorks.API as Start Up Project AdventureWorks.API/Program.cs has ApplyMigrations()
    • After migrations you can update the DB
    Package Manager Console: Update-Database
    Command Line: dotnet ef database update

  1. Steps to handle new migrations
    1. Using Package Manager Console (PMC)

      • Open PMC: In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console.

      • Select the Project: Ensure that the Default Project dropdown in the PMC is set to the project containing your DbContext in this case AdventureWorks.Infrastructure

      • Run the Migration Command:

        Add-Migration MigrationName
      • Review the Generated Migration under AdventureWorks.Infrastructure/Migrations

      • Apply the Migration

            Update-Database
    2. Using Command line

      • Open a Terminal or Command Prompt: Navigate to the root folder of the project.

        • Ensure the .NET CLI tools are installed and accessible. Use dotnet --version to confirm
      • Run the Migration Command:

            dotnet ef migrations add MigrationName
      • Review the Generated Migration under AdventureWorks.Infrastructure/Migrations

      • Apply the Migration

            dotnet ef database update
    3. Review the __EFMigrationsHistory table into the DB and check the changes.

Project Structure

AdventureWorks.sln/
│   ├── AdventureWorks.API/            # Presentation Layer (Start Up)
│   │   ├── Controllers                # Endpoints
│   │   ├── Middleware                 # Middlewares: Handler global Exceptions 
│   │
│   ├── AdventureWorks.Domain/         # Domain Model Layer
│   │   └── Entities
│   │
│   ├── AdventureWorks.Application/         # Application Layer (CQRS)
│   │   └── Abstractions                    # Interface Segregation Pinciple
│   │   └── DependencyInjection.cs          # DI Configuration / Mediatr
│   │
│   ├── AdventureWorks.Infrastructure/      # Infrastructure Layer
│   │   └── Migrations                      # EF Core
│   │   └── Persistence                     # DBContext
│   │   └── Repositories                    # Repository Pattern
│   ├── test
│   │   └──AdventureWorks.Application.UnitTests  #xUnit Moq FluentAssertions
├── .editorconfig              # Environment VS conventions
└── README.md                  # Project docs

About

Clean Architecture Project Using AdventureWorks2022 DB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages