Add EF Core data annotations for table and FK mapping

Added [Table] and [ForeignKey] attributes to entity classes to explicitly map them to database tables/views and define relationships. Updated using directives as needed. Improves entity mapping clarity and robustness against schema changes.
This commit is contained in:
2025-12-12 13:55:22 +01:00
parent 46b7ae29cd
commit 6b036f4f91
8 changed files with 32 additions and 7 deletions

View File

@@ -1,5 +1,8 @@
namespace ReC.Domain.Entities; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBDD_CONNECTION")]
public class Connection public class Connection
{ {
public short? Id { get; set; } public short? Id { get; set; }

View File

@@ -1,5 +1,8 @@
namespace ReC.Domain.Entities; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ENDPOINT")]
public class Endpoint public class Endpoint
{ {
public long Id { get; set; } public long Id { get; set; }

View File

@@ -1,9 +1,9 @@
using ReC.Domain.Constants; using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities; namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ENDPOINT_AUTH")]
public class EndpointAuth public class EndpointAuth
{ {
public long? Id { get; set; } public long? Id { get; set; }

View File

@@ -1,10 +1,13 @@
namespace ReC.Domain.Entities; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
/// <summary> /// <summary>
/// Represents the TBREC_CFG_ENDPOINT_PARAMS table. /// Represents the TBREC_CFG_ENDPOINT_PARAMS table.
/// All properties are nullable to provide flexibility on the database side, /// All properties are nullable to provide flexibility on the database side,
/// preventing breaking changes if columns are altered to be nullable in production. /// preventing breaking changes if columns are altered to be nullable in production.
/// </summary> /// </summary>
[Table("TBREC_CFG_ENDPOINT_PARAMS", Schema = "dbo")]
public class EndpointParam public class EndpointParam
{ {
public long? Id { get; set; } public long? Id { get; set; }

View File

@@ -1,5 +1,8 @@
namespace ReC.Domain.Entities; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_OUT_RESULT", Schema = "dbo")]
public class OutRes public class OutRes
{ {
public long? Id { get; set; } public long? Id { get; set; }

View File

@@ -1,5 +1,8 @@
namespace ReC.Domain.Entities; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_PROFILE", Schema = "dbo")]
public class Profile public class Profile
{ {
public long Id { get; set; } public long Id { get; set; }

View File

@@ -1,7 +1,9 @@
using ReC.Domain.Constants; using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities; namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ACTION")]
public class RecAction public class RecAction
{ {
public long? Id { get; set; } public long? Id { get; set; }

View File

@@ -1,5 +1,4 @@
using ReC.Domain.Constants; using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities; namespace ReC.Domain.Entities;
@@ -12,14 +11,17 @@ namespace ReC.Domain.Entities;
/// runtime mapping errors and ensures the application can handle schema changes without /// runtime mapping errors and ensures the application can handle schema changes without
/// requiring immediate code updates. /// requiring immediate code updates.
/// </summary> /// </summary>
[Table("VWREC_ACTION", Schema = "dbo")]
public class RecActionView public class RecActionView
{ {
public required long Id { get; set; } public required long Id { get; set; }
[ForeignKey("Id")]
public RecAction? Root { get; set; } public RecAction? Root { get; set; }
public long? ProfileId { get; set; } public long? ProfileId { get; set; }
[ForeignKey("ProfileId")]
public Profile? Profile { get; set; } public Profile? Profile { get; set; }
public string? ProfileName { get; set; } public string? ProfileName { get; set; }
@@ -30,6 +32,9 @@ public class RecActionView
public long? EndpointId { get; set; } public long? EndpointId { get; set; }
[ForeignKey("EndpointId")]
public Endpoint? Endpoint { get; set; }
public string? EndpointUri { get; set; } public string? EndpointUri { get; set; }
public long? EndpointAuthId { get; set; } public long? EndpointAuthId { get; set; }
@@ -59,6 +64,9 @@ public class RecActionView
public short? SqlConnectionId { get; set; } public short? SqlConnectionId { get; set; }
[ForeignKey("SqlConnectionId")]
public Connection? SqlConnection { get; set; }
public string? SqlConnectionServer { get; set; } public string? SqlConnectionServer { get; set; }
public string? SqlConnectionDb { get; set; } public string? SqlConnectionDb { get; set; }