Adding database in Azure –part 26

Now getting the database – needed for historic data.

When I go to Create New Database in Azure Portal , there are many types of Database (mongo, postgres, many others) – the easy choice, for me, is SqlServer ( even if the tables are not be updated – the exchange rates does not change a lot). There is something that is easy to deploy a WebApp : WebApp + Sql

But I wil create a new one – Azure Sql Managed Instance – the price for 4 vCore is > 400 EUR. Sure do not want this…

So I decided yo have SqlServer, with a database with 2 GB storage  – smaller price, like 4.21 per month– for a normal person.

I can access with SSMS to create tables – and then I generate the script

CREATE TABLE [dbo].[NBR](
[ExchangeFrom] [nvarchar](50) NOT NULL,
[ExchangeTo] [nvarchar](50) NOT NULL,
[Date] [date] NOT NULL,
[ExchangeValue] [decimal](18, 6) NOT NULL,
CONSTRAINT [PK_NBR] PRIMARY KEY CLUSTERED
(
[ExchangeFrom] ASC,
[ExchangeTo] ASC,
[Date] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

 

Create an ISave interface ( trying to cope with CQRS) .

Now I want to scaffold C# from database like https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

Installing

dotnet tool install –global dotnet-ef

gives error about versioning

dotnet tool install –global dotnet-ef –version 3.0.0

SUccess!

Now trying to scaffold

dotnet ef dbcontext scaffold “Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -o Models

Error – does not find project

Ok. Run in the folder with the project. Now it does not like .NET Standard – wants .NET Core . Changed in .csproj <TargetFramework>netcoreapp3.0</TargetFramework>

Now it says:

Your startup project ‘InfovalutarDB’ doesn’t reference Microsoft.EntityFrameworkCore.Design.

Adding the NuGet Package

Now the command line

dotnet ef dbcontext scaffold “Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -o Models

Works!

Reading about storing connection strings safe:

http://go.microsoft.com/fwlink/?LinkId=723263

Figuring a way to use either inmemory database( for fast testing) or sqlserver

var config = ConfigurationManager.ConnectionStrings[“DB”];
var opt= new DbContextOptionsBuilder<InfoValutarContext>();
if (config == null)
{
opt.UseInMemoryDatabase(“write”);
}
else
{
opt.UseSqlServer(config.ConnectionString);
}

var cnt = new InfoValutarContext(opt.Options);

 

So a new Test created:

ISave s = new SaveSqlServer();
var response = await File.ReadAllTextAsync(Path.Combine(“Data”, “20191020bnr.txt”));
var m = new MockHttpMessageHandler();
m.When(“https://www.bnr.ro/nbrfxrates.xml”)
.Respond(“application/text”, response);

var nbr = new GetNBRExchange(m);
var data = await nbr.GetActualRates().ToArrayAsync();
var nr= await s.Save(data);
Assert.Equal(nr, data.Length);

 

And modified in the Docker file to restore this new project

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe