Files
gwms/GWMS.Data
2021-06-19 17:40:25 +02:00
..
2021-06-19 17:40:17 +02:00
2021-06-07 19:13:27 +02:00
2021-06-19 17:40:17 +02:00
2021-05-28 19:08:23 +02:00
2021-05-28 19:08:23 +02:00
2021-05-31 17:34:18 +02:00
2021-05-31 18:00:02 +02:00
2021-05-31 18:00:02 +02:00
2021-06-01 18:57:48 +02:00

Appunti gestione GWMS DB

Per la gestione dell'accesso al DB si opera con EFCore --> app blazor server

Scaffolding

Per generare le classi da un DB esistente con cui operare EFCore CodeFirst usare lo scaffolding coi seguenti comandi. Attenzione: la classe DbContext viene creata INSIEME alle viste nella folder DatabaseModel (nell'esempio seguente...)

DB iniziale

Scaffold-DbContext "Server=SQL2016DEV;Database=GWMS;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DatabaseModels

SOLO di tabelle/viste selezionate (con force update)

Scaffold-DbContext "Server=SQL2016DEV;Database=GWMS;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DatabaseModels -Tables nome_tabella, nome_vista

Reset DB MsSql

Per resettare un db MsSql (cancellando tutto x poter ridare update) eseguire il seguente codice

-- drop constraints
DECLARE @DropConstraints NVARCHAR(max) = ''
SELECT @DropConstraints += 'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.'
                        +  QUOTENAME(OBJECT_NAME(parent_object_id)) + ' ' + 'DROP CONSTRAINT' + QUOTENAME(name)
FROM sys.foreign_keys
EXECUTE sp_executesql @DropConstraints;
GO
  
-- drop tables
DECLARE @DropTables NVARCHAR(max) = ''
SELECT @DropTables += 'DROP TABLE ' + QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
EXECUTE sp_executesql @DropTables;
GO

Il DB viene poi rigenerato dal Package Maganer console con

Update-Database

Impiego multi provider

In caso di scelta per impiego di più providers (MsSql, MariaDB, SqlLite, ...) è necessario gestire in modo diverso le classi di inizializzazione del DbContenxt. Non ancora verificato, ma da approfondire secondo i seguenti links:

Ottimizzazioni e spunti

Alcuni spunti da approfondire:

Migrations

Approfondimenti:

Approfondimenti

Qualche link di approfondimento: