Refactor RecAction mapping to Fluent API in DbContext

Moved all RecAction table and column mappings from data annotations in the entity class to Fluent API configuration in RecDbContext. Also consolidated the OutRes relationship setup into the new configuration block, removing redundant mapping code. RecAction is now a plain class without EF attributes.
This commit is contained in:
2025-12-10 12:04:43 +01:00
parent 674c14dd7c
commit b79fcf936b
2 changed files with 31 additions and 32 deletions

View File

@@ -1,73 +1,47 @@
using System.ComponentModel.DataAnnotations; namespace ReC.Domain.Entities;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ACTION")]
public class RecAction public class RecAction
{ {
[Key]
[Column("GUID")]
public long? Id { get; set; } public long? Id { get; set; }
[Column("PROFILE_ID")]
public long? ProfileId { get; set; } public long? ProfileId { get; set; }
[ForeignKey("ProfileId")]
public Profile? Profile { get; set; } public Profile? Profile { get; set; }
[Column("ACTIVE")]
public bool? Active { get; set; } public bool? Active { get; set; }
[Column("SEQUENCE")]
public byte? Sequence { get; set; } public byte? Sequence { get; set; }
[Column("ENDPOINT_ID")]
public long? EndpointId { get; set; } public long? EndpointId { get; set; }
[ForeignKey("EndpointId")]
public Endpoint? Endpoint { get; set; } public Endpoint? Endpoint { get; set; }
[Column("ENDPOINT_AUTH_ID")]
public long? EndpointAuthId { get; set; } public long? EndpointAuthId { get; set; }
[ForeignKey("EndpointAuthId")]
public EndpointAuth? EndpointAuth { get; set; } public EndpointAuth? EndpointAuth { get; set; }
[Column("ENDPOINT_PARAMS_ID")]
public short? EndpointParamsId { get; set; } public short? EndpointParamsId { get; set; }
[Column("SQL_CONNECTION_ID")]
public short? SqlConnectionId { get; set; } public short? SqlConnectionId { get; set; }
[ForeignKey("SqlConnectionId")]
public Connection? SqlConnection { get; set; } public Connection? SqlConnection { get; set; }
[Column("TYPE")]
public string? Type { get; set; } public string? Type { get; set; }
[Column("PREPROCESSING_QUERY")]
public string? PreprocessingQuery { get; set; } public string? PreprocessingQuery { get; set; }
[Column("HEADER_QUERY")]
public string? HeaderQuery { get; set; } public string? HeaderQuery { get; set; }
[Column("BODY_QUERY")]
public string? BodyQuery { get; set; } public string? BodyQuery { get; set; }
[Column("POSTPROCESSING_QUERY")]
public string? PostprocessingQuery { get; set; } public string? PostprocessingQuery { get; set; }
[Column("ADDED_WHO")]
public string? AddedWho { get; set; } public string? AddedWho { get; set; }
[Column("ADDED_WHEN")]
public DateTime? AddedWhen { get; set; } public DateTime? AddedWhen { get; set; }
[Column("CHANGED_WHO")]
public string? ChangedWho { get; set; } public string? ChangedWho { get; set; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; set; } public DateTime? ChangedWhen { get; set; }
public OutRes? OutRes { get; set; } public OutRes? OutRes { get; set; }

View File

@@ -162,6 +162,36 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN"); b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
}); });
modelBuilder.Entity<RecAction>(b =>
{
b.ToTable("TBREC_CFG_ACTION");
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasColumnName("GUID");
b.Property(e => e.ProfileId).HasColumnName("PROFILE_ID");
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Sequence).HasColumnName("SEQUENCE");
b.Property(e => e.EndpointId).HasColumnName("ENDPOINT_ID");
b.Property(e => e.EndpointAuthId).HasColumnName("ENDPOINT_AUTH_ID");
b.Property(e => e.EndpointParamsId).HasColumnName("ENDPOINT_PARAMS_ID");
b.Property(e => e.SqlConnectionId).HasColumnName("SQL_CONNECTION_ID");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.PreprocessingQuery).HasColumnName("PREPROCESSING_QUERY");
b.Property(e => e.HeaderQuery).HasColumnName("HEADER_QUERY");
b.Property(e => e.BodyQuery).HasColumnName("BODY_QUERY");
b.Property(e => e.PostprocessingQuery).HasColumnName("POSTPROCESSING_QUERY");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
b.HasOne(act => act.OutRes)
.WithOne(res => res.Action)
.HasForeignKey<OutRes>(res => res.ActionId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<RecActionView>(b => modelBuilder.Entity<RecActionView>(b =>
{ {
b.ToTable("VWREC_ACTION", "dbo"); b.ToTable("VWREC_ACTION", "dbo");
@@ -209,10 +239,5 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
b.Property(e => e.RawBody).HasColumnName("REQUEST_BODY"); b.Property(e => e.RawBody).HasColumnName("REQUEST_BODY");
}); });
modelBuilder.Entity<RecAction>()
.HasOne(act => act.OutRes)
.WithOne(res => res.Action)
.HasForeignKey<OutRes>(res => res.ActionId)
.OnDelete(DeleteBehavior.Cascade);
} }
} }