Skip to content

I made this for fellow Mac users - Are you tired of setting up DbContext on your mac and dealing with Docker setup? Well, I am. That's why I created this ASP.NET 7 template—with Docker all set up and ready to go. Read the Readme for all the details

Notifications You must be signed in to change notification settings

K2adir/ASP-Net-7-on-Mac-With-Docker-SQL-Server-Template

Repository files navigation

I just realized, I named the program as Net8, but it's Net 7. This is okay, follow the guide.

Hello Mac Users

Aren't you tired of Microsoft's lack of proper documentation for Mac users and how horrible the DX (Developer Experience) is?

I know I am. Here you can have my ready-to-go template.

You only need 4 files from this repo.

Data/DbContext.cs

Program.cs, for this line

builder.Services.AddDbContext<MovieDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("MovieDbContext")));

Models/Movie.cs

appsettings.json for the connection string setup.

Project Setup

This template includes a predefined connection string in appsettings.json and utilizes Docker for database management.

Docker Image

We use the Microsoft Azure SQL Edge Docker image, which can be found here.

Installation and Running:

  1. Install the Docker image from the provided link.
  2. Run it on your machine. My instance is running at Port 1433:1433.
  3. My docker image's Username (User=sa) and Password (Password=Admin@123) are written in the connection string. You may want to change it to something else.

Configuration Details

Connection String

If your local host is something other than 127.0.0.1, you will need to make adjustments. Here’s an example of how to write it in appsettings.json:

{
  "ConnectionStrings": {
    "MovieDbContext": "Server=tcp:127.0.0.1,1433;Database=NetDemo;MultipleActiveResultSets=true;User=sa;Password=Admin@123; TrustServerCertificate=true;"
  }
}

My file is included in the repo.

Project Setup Instructions

Initial Setup

After cloning the repository, open your terminal and execute the following command to install the missing NuGet packages:

dotnet restore

If this step fails, review the Data/DbContext and Program.cs files for any errors related to missing packages.

Managing Database Migrations

Once the NuGet packages are restored, you can proceed with setting up and managing your database migrations using Entity Framework:

Create a New Migration:

To create a new migration, run the following command in your terminal. Feel free to change "YourMigrationName"

dotnet ef migrations add YourMigrationName

Update the Database:

Apply the latest migrations to update the database by running:

dotnet ef database update

Voala! (or something like that) check your database using Azure Data Studio, you can download it for free from Microsoft..

For Azure Data Studio, use the following settings

Connection type: Microsoft sql server

input type: parameters

server: localhost

username: sa (username of your running docker instance)

password: (docker password)

trust server certificate: True

and hit connect.

About

I made this for fellow Mac users - Are you tired of setting up DbContext on your mac and dealing with Docker setup? Well, I am. That's why I created this ASP.NET 7 template—with Docker all set up and ready to go. Read the Readme for all the details

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published