aggiunto setup per interazione con db
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SMGen.Data.DbModels
|
||||
{
|
||||
[Table("TransizioneIngressi")]
|
||||
public class TransizioneIngressiModel
|
||||
{
|
||||
public int IdxFamigliaIngresso { get; set; } = 0;
|
||||
public int IdxMicroStato { get; set; } = 0;
|
||||
public int ValoreIngresso { get; set; } = 0;
|
||||
public int IdxTipoEvento { get; set; } = 0;
|
||||
public int next_IdxMicroStato { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SMGen.Data.DbModels
|
||||
{
|
||||
[Table("TransizioneIngressi_Chk")]
|
||||
public class TransizioneIngressiTempModel
|
||||
{
|
||||
public int IdxFamigliaIngresso { get; set; } = 0;
|
||||
public int IdxMicroStato { get; set; } = 0;
|
||||
public int ValoreIngresso { get; set; } = 0;
|
||||
public int IdxTipoEvento { get; set; } = 0;
|
||||
public int next_IdxMicroStato { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using SMGen.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SMGen.Data
|
||||
{
|
||||
public partial class SMGDataContext : DbContext
|
||||
{
|
||||
public SMGDataContext()
|
||||
{ }
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
public SMGDataContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
|
||||
try
|
||||
{
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 011");
|
||||
}
|
||||
}
|
||||
|
||||
public SMGDataContext(DbContextOptions<SMGDataContext> options, IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
bool disableMigrate = _configuration.GetValue<bool>("SetupOpt:DisableMigrate");
|
||||
if (!disableMigrate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 02");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual DbSet<TransizioneIngressiTempModel> DbSetTranIngTemp { get; set; } = null!;
|
||||
|
||||
public void DbForceMigrate()
|
||||
{
|
||||
// verifico SE devo eseguire la migration del DB IDENT...
|
||||
bool disableMigrate = _configuration.GetValue<bool>("SetupOpt:DisableMigrate");
|
||||
if (!disableMigrate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
Log.Info("DbForceMigrate: done!");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "DbForceMigrate: Exception during context initialization 01");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("WDC.DB");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UseCollation("Latin1_General_CI_AS");
|
||||
modelBuilder.Entity<TransizioneIngressiTempModel>().HasKey(c => new { c.IdxFamigliaIngresso, c.IdxMicroStato, c.ValoreIngresso });
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="SMGenDataContext.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EgwCoreLib.Utils" Version="1.4.2307.2515" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="DTO\" />
|
||||
<Folder Include="SqlScripts\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,131 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SMGen.Data
|
||||
{
|
||||
public partial class SMGenDataContext : DbContext
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public SMGenDataContext()
|
||||
{
|
||||
}
|
||||
|
||||
public SMGenDataContext(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 02");
|
||||
}
|
||||
}
|
||||
|
||||
public SMGenDataContext(DbContextOptions<SMGenDataContext> options, IConfiguration configuration) : base(options)
|
||||
{
|
||||
_configuration = configuration;
|
||||
// verifico SE devo eseguire la migration del DB IDENT...
|
||||
bool disableMigrate = _configuration.GetValue<bool>("SetupOpt:DisableWDCMigrate");
|
||||
if (!disableMigrate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Exception during context initialization 02");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
//public virtual DbSet<CompanyModel> DbSetCompany { get; set; } = null!;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void DbForceMigrate()
|
||||
{
|
||||
// verifico SE devo eseguire la migration del DB IDENT...
|
||||
bool disableMigrate = _configuration.GetValue<bool>("SetupOpt:DisableWDCMigrate");
|
||||
if (!disableMigrate)
|
||||
{
|
||||
try
|
||||
{
|
||||
// se non ci fosse... crea o migra!
|
||||
Database.Migrate();
|
||||
Log.Info("DbForceMigrate: done!");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "DbForceMigrate: Exception during context initialization 01");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string connString = _configuration.GetConnectionString("WDC.DB");
|
||||
if (!string.IsNullOrEmpty(connString))
|
||||
{
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
}
|
||||
else
|
||||
{
|
||||
//// dev
|
||||
//optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=WebDoorCreator;Trusted_Connection=True;", e => e.UseHierarchyId());
|
||||
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=WebDoorCreator;Trusted_Connection=True;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UseCollation("Latin1_General_CI_AS");
|
||||
|
||||
|
||||
//modelBuilder.Seed();
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IConfiguration _configuration;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Methods
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33815.320
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMGen", "SMGen\SMGen.csproj", "{1224887B-2A4F-433C-ADB6-51683E2ADBA7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMGen.Data", "SMGen.Data\SMGen.Data.csproj", "{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1224887B-2A4F-433C-ADB6-51683E2ADBA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CF2D0A2F-DED0-4D5D-8C31-099B3C3ED16D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
+14
-1
@@ -23,8 +23,21 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EgwCoreLib.Razor" Version="1.4.2307.308" />
|
||||
<PackageReference Include="EgwCoreLib.Razor" Version="1.4.2307.2515" />
|
||||
<PackageReference Include="EgwCoreLib.Utils" Version="1.4.2307.2515" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SMGen.Data\SMGen.Data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
@using SMGen.Components
|
||||
@using EgwCoreLib.Razor
|
||||
@using EgwCoreLib.Razor.Data
|
||||
@using SMGen.Data
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Redis": "nkcredis.steamware.net:6379, DefaultDatabase=11, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false, password=BtN9Py1wtLfLRvmzWnOPJ7RytDM+CLiVsJ/16zduNTlV8IOPGNrtzJSXPUnImA5PqmUMhKaUqo9NdHIG",
|
||||
"SMGen.DB": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=SMGen.UI;"
|
||||
},
|
||||
"ServerConf": {
|
||||
"ProcCsvRootPath": "Temp\\Rules\\PROCESSED"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user