Skip to content

Demo app for learning how to access SQL Server, PostgreSQL, Cosmos DB and Redis from C#. *Coming soon!* Aspire integration.

Notifications You must be signed in to change notification settings

mikewild-wcl/DatabaseSampler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Samples

A site with samples for multiple databases. The solution uses Aspire, so all dependencies are defined in the AppHost project.

Testing

Tests use xUnit + Shouldly.

Run all tests:

dotnet test

Only a few parameters are needed in the AppHost appsettings.json to run on a local machine:

Note: do not commit secrets. Sensitive values like passwords should be set in the user secrets file.

  "Parameters": {
    "CosmosDBDatabaseId": "ToDoList",
    "CosmosDBExpenseCollectionId": "Items",
    "PostgreSQLPassword": "",
    "SqlServerPassword": ""
  },

Note: package versions are managed centrally in Directory.Packages.props.

Database migrations

Databases are created in AppHost using Aspire. The PostgreSQL database uses EF Core migrations, and the SQL Server database uses DbUp initialisation - these are both done in separate projects run at startup (or run in CI/CD provisioning for cloud scenarios.)

Migration - using Package Manager

Make sure the main web project is set as the startup project, and in the Package Manager Console set the Default Project to DatabaseSampler.Application. Run

Add-Migration InitialStudentEntities -Context DatabaseSampler.Application.Data.StudentDbContext 
Update-Database -Context DatabaseSampler.Application.Data.StudentDbContext

Using dotnet ef tools:

See Getting Started with EF Core

Install with :

dotnet tool install --global dotnet-ef

or update with

dotnet tool update --global dotnet-ef

Make sure the project has a reference to Microsoft.EntityFrameworkCore.Design and Microsoft.EntityFrameworkCore.Tools packages, and that the main web project is set as the startup project. Then run the following commands from the project directory: To set up the initial migration and update the database, run the following commands from the project directory:

dotnet ef migrations add InitialCreate

You can update the database, directly with

dotnet ef database update

but since we are using Aspire the update will be handled by the Migrations project.

Functions setup

local.settings.json is part of the project and is checked into git. There is no need to add any values because Aspire will handle all environment settings.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "ASPNETCORE_URLS": "http://localhost:60809"
  },
  "Host": {
    "CORS": "*",
    "CORSCredentials": false
  }
}

Logger messages

Log message event id ranges:

  • 000-099: Application
  • 100-199: Bogus
  • 200-299: Cosmos DB
  • 300-399: PostgreSQL
  • 400-499: SQL Server
  • 500-599: MongoDB
  • 800-899: Azure Functions

Articles

Cosmos DB MVC

Cosmos DB .NET Core

Official tutorial

Functions V3 Preview Setup

CosmosDb - Errors on Inserting New Data

Code Downloads

Cosmos Book Code

Azure ML

First ML experiment with R - Azure Machine Learning Install remotes::install_github('https://github.com/Azure/azureml-sdk-for-r', INSTALL_opts=c("--no-multiarch"))

Deployment - see https://github.com/Microsoft/AKSDeploymentTutorial or updated https://github.com/microsoft/AKSDeploymentTutorialAML

Developer setup

Requirements

Functions (dotnet-isolated)

Endpoints:

See

Install Azure Functions Core Tools: See Azure Functions Core Tools | Installing with npm:

npm i -g azure-functions-core-tools@4 --unsafe-perm true

or winget:

winget install Microsoft.Azure.FunctionsCoreTools
https://learn.microsoft.com/en-gb/azure/azure-functions/functions-run-local?tabs=windows%2Cisolated-process%2Cnode-v4%2Cpython-v2%2Chttp-trigger%2Ccontainer-apps&pivots=programming-language-csharp#install-the-azure-functions-core-tools

Then run from the project directory using

func host start --verbose

About

Demo app for learning how to access SQL Server, PostgreSQL, Cosmos DB and Redis from C#. *Coming soon!* Aspire integration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published