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

Repository files navigation

Database Samples

A site with samples for multiple databases

The following needs to be in appsettings.json to run on a local machine:

  "SqlConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Locations;Integrated Security=True;MultipleActiveResultSets=True;",
  "AzureSearchConfiguration":
  {
    "SearchServiceName": "Put your search service name here",
    "SearchServiceAdminApiKey": "Put your primary or secondary API key here",
    "SearchServiceQueryApiKey": "Put your query API key here"
  },
  "PostgreSQL": {
		"ConnectionString": "server=localhost;port=5432;userid=postgres;database=students;",
		"DbPassword": "YourPasswordHere"
  },
  "CosmosConnectionString": "TODO",
  "CosmosConnectionString": "<connection_string_>",
  "CosmosConfig": {
    "EndpointUri": "https://localhost:8081/",
    "AuthorizationKey": "<key>",
    "DatabaseId": "ToDoList",
    "ExpenseCollectionId": "Items"
  },
  "RedisConnectionString": "localhost:6379",
  "SqlConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Locations;Integrated Security=True;MultipleActiveResultSets=True;"

Make sure there is a PostgresSQL database matching the connection string (e.g. students).

DROP DATABASE IF EXISTS students;
CREATE DATABASE students;

Set up entities: 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

Create a SQL Server database and table:

DROP DATABASE Locations;
GO
CREATE DATABASE Locations;
--DROP TABLE [dbo].[PostcodeLookup]
GO
--TODO: Consider Postcode as Primary Key    
CREATE TABLE [dbo].[PostcodeLookup](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Postcode] [varchar](10) NOT NULL,
	[DistrictCode] [varchar](10) NOT NULL,
	[Latitude] [decimal](9, 6) NULL,
	[Longitude] [decimal](9, 6) NULL,
	[Location] [geography] NULL,
	[IsTerminated] [bit] NOT NULL,
	[TerminatedYear] [smallint] NULL,
	[TerminatedMonth] [smallint] NULL,
	[Created] [datetime2](7) NOT NULL DEFAULT (getutcdate())
 CONSTRAINT [PK_PostcodeLookup] PRIMARY KEY CLUSTERED ([Id] ASC),
 INDEX [IX_PostcodeLookup_Postcode] NONCLUSTERED ([Postcode])
)
GO
CREATE SPATIAL INDEX [SPATIAL_PostcodeLookup_Location] 
   ON [dbo].[PostcodeLookup](Location);
GO

Functions setup

Add local.settings.json file with:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "PostgreSQLConnectionString": "server=localhost;port=5432;userid=postgres;database=students;",
    "PostgreSQLDbPassword": ""
  }
}

Articles

Cosmos DB MVC

Cosmos DB .NET Core

Official tutorial

Functions V3 Preview Setup

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

Azure Search

look for data from query below, index it to search by qualification title

--(localdb)\ProjectsV13 --use [Matching.Live]

select * from Provider p inner join providervenue pv on pv.ProviderId = p.Id inner join ProviderQualification pvq on pvq.ProviderVenueId = pv.Id inner join Qualification q on q.Id = pvq.QualificationId inner join QualificationRouteMapping qrm on qrm.QualificationId = q.Id inner join Route r on r.Id = qrm.RouteId

Developer setup

Requirements

Environment Setup

The default development environment uses docker containers to host the following dependencies.

  • Redis

On first setup run the following command from /containers/ to create the docker container images:

docker-compose build

To start the container run:

docker-compose up -d

To stop the container run:

docker-compose down

You can view the state of the running containers using:

docker ps -a

To check all details including volumes and network suse

docker inspect redis

To check network details use

docker network inspect containers_redis-network

To see all networks use

docker network ls

You can start an interactive shell inside the container with

docker exec -it redis /bin/bash

To see logs in the container use

docker logs redis

or to see an interactive view of logs

docker logs -f redis

Functions in .NET 5.0

See

Until VS2019 is updated, the functions project cannot be run from there.

Install the latest functions tools:

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

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