Refactor Connection entity to use Fluent API mapping

Removed data annotations from Connection.cs and moved all table and column mapping to RecDbContext's OnModelCreating using the Fluent API. This centralizes entity configuration and removes dependencies on DataAnnotations in the entity class.
This commit is contained in:
2025-12-10 11:56:14 +01:00
parent 8bc9b85049
commit 13346b610a
2 changed files with 26 additions and 21 deletions

View File

@@ -1,52 +1,32 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
namespace ReC.Domain.Entities;
[Table("TBDD_CONNECTION")]
public class Connection
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("GUID")]
public short? Id { get; set; }
[Column("BEZEICHNUNG")]
public string? Bezeichnung { get; set; }
[Column("SQL_PROVIDER")]
public string? SqlProvider { get; set; }
[Column("SERVER")]
public string? Server { get; set; }
[Column("DATENBANK")]
public string? Datenbank { get; set; }
[Column("USERNAME")]
public string? Username { get; set; }
[Column("PASSWORD")]
public string? Password { get; set; }
[Column("BEMERKUNG")]
public string? Bemerkung { get; set; }
[Column("AKTIV")]
public bool? Aktiv { get; set; }
[Column("ERSTELLTWER")]
public string? ErstelltWer { get; set; }
[Column("ERSTELLTWANN")]
public DateTime? ErstelltWann { get; set; }
[Column("GEANDERTWER")]
public string? GeandertWer { get; set; }
[Column("GEAENDERTWANN")]
public DateTime? GeaendertWann { get; set; }
[Column("SYS_CONNECTION")]
public bool? SysConnection { get; set; }
}

View File

@@ -30,6 +30,31 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Connection>(b =>
{
b.ToTable("TBDD_CONNECTION");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.Bezeichnung).HasColumnName("BEZEICHNUNG");
b.Property(e => e.SqlProvider).HasColumnName("SQL_PROVIDER");
b.Property(e => e.Server).HasColumnName("SERVER");
b.Property(e => e.Datenbank).HasColumnName("DATENBANK");
b.Property(e => e.Username).HasColumnName("USERNAME");
b.Property(e => e.Password).HasColumnName("PASSWORD");
b.Property(e => e.Bemerkung).HasColumnName("BEMERKUNG");
b.Property(e => e.Aktiv).HasColumnName("AKTIV");
b.Property(e => e.ErstelltWer).HasColumnName("ERSTELLTWER");
b.Property(e => e.ErstelltWann).HasColumnName("ERSTELLTWANN");
b.Property(e => e.GeandertWer).HasColumnName("GEANDERTWER");
b.Property(e => e.GeaendertWann).HasColumnName("GEAENDERTWANN");
b.Property(e => e.SysConnection).HasColumnName("SYS_CONNECTION");
});
modelBuilder.Entity<EndpointParam>(b =>
{
b.ToTable("TBREC_CFG_ENDPOINT_PARAMS", "dbo");