57c41c7a60
- fix naming DbModels
113 lines
3.2 KiB
C#
113 lines
3.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.FileData.DbModels;
|
|
using NLog;
|
|
|
|
namespace MP.FileData
|
|
{
|
|
public partial class MoonPro_ProgContext : DbContext
|
|
{
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private IConfiguration _configuration;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
|
|
public MoonPro_ProgContext()
|
|
{
|
|
}
|
|
|
|
public MoonPro_ProgContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
try
|
|
{
|
|
// se non ci fosse... crea o migra!
|
|
Database.Migrate();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error(exc, "Exception during context initialization 01");
|
|
}
|
|
}
|
|
|
|
public MoonPro_ProgContext(DbContextOptions<MoonPro_ProgContext> options) : base(options)
|
|
{
|
|
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<ArchMaccModel> DbSetArchMacc { get; set; }
|
|
public virtual DbSet<FileModel> DbSetProgFile { get; set; }
|
|
public virtual DbSet<TagModel> DbSetTags { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
if (!optionsBuilder.IsConfigured)
|
|
{
|
|
string connString = _configuration.GetConnectionString("MP.Prog");
|
|
if (!string.IsNullOrEmpty(connString))
|
|
{
|
|
optionsBuilder.UseSqlServer(connString);
|
|
}
|
|
else
|
|
{
|
|
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_PROG;Trusted_Connection=True;");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
|
|
|
|
// fix valori default
|
|
modelBuilder.Entity<FileModel>(entity =>
|
|
{
|
|
entity.Property(e => e.UserAppr)
|
|
.HasMaxLength(250)
|
|
.IsRequired()
|
|
.HasDefaultValueSql("('')");
|
|
});
|
|
|
|
|
|
modelBuilder.Seed();
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |