Refactor DbModel options to use generic entity mapping

Replaces strongly-typed view options classes with a generic EntityOptions class and a dictionary-based configuration for entity-to-view and property-to-column mappings. Updates appsettings.DbModel.json to match the new structure. Refactors RecDbContext to use extension methods for mapping configuration. Removes obsolete options classes and simplifies exception handling for missing mappings. This change improves flexibility and maintainability of database view configuration.
This commit is contained in:
2026-03-25 15:25:29 +01:00
parent e761fbd1ca
commit 1467acc4a1
13 changed files with 253 additions and 300 deletions

View File

@@ -0,0 +1,8 @@
namespace ReC.Application.Common.Exceptions;
public class DbModelConfigurationException : Exception
{
public DbModelConfigurationException() { }
public DbModelConfigurationException(string message) : base(message) { }
}

View File

@@ -1,6 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class BodyQueryResultOptions
{
public string RawBody { get; set; } = "REQUEST_BODY";
}

View File

@@ -2,15 +2,5 @@ namespace ReC.Application.Common.Options.DbModel;
public class DbModelOptions
{
public RecActionViewOptions RecActionView { get; set; } = new();
public ProfileViewOptions ProfileView { get; set; } = new();
public ResultViewOptions ResultView { get; set; } = new();
public HeaderQueryResultOptions HeaderQueryResult { get; set; } = new();
public BodyQueryResultOptions BodyQueryResult { get; set; } = new();
public InsertObjectResultOptions InsertObjectResult { get; set; } = new();
public Dictionary<string, EntityOptions> Entities { get; set; } = [];
}

View File

@@ -0,0 +1,25 @@
using ReC.Application.Common.Exceptions;
namespace ReC.Application.Common.Options.DbModel;
public static class DbModelOptionsExtensions
{
public static EntityOptions GetEntity(this DbModelOptions options, string entityName)
{
if (options.Entities.TryGetValue(entityName, out var entity))
return entity;
throw new DbModelConfigurationException(
$"Entity '{entityName}' is not configured in DbModel options.");
}
public static string GetColumn(this EntityOptions entity, string entityName, string propertyName)
{
if (entity.ColumnMappings.TryGetValue(propertyName, out var columnName))
return columnName;
var viewDisplay = entity.Name ?? entityName;
throw new DbModelConfigurationException(
$"Column mapping for property '{propertyName}' is not configured for entity '{viewDisplay}'.");
}
}

View File

@@ -0,0 +1,10 @@
namespace ReC.Application.Common.Options.DbModel;
public class EntityOptions
{
public string? Name { get; set; }
public string Schema { get; set; } = "dbo";
public Dictionary<string, string> ColumnMappings { get; set; } = [];
}

View File

@@ -1,6 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class HeaderQueryResultOptions
{
public string RawHeader { get; set; } = "REQUEST_HEADER";
}

View File

@@ -1,6 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class InsertObjectResultOptions
{
public string NewObjectId { get; set; } = "oGUID";
}

View File

@@ -1,25 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class ProfileViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_PROFILE", Schema = "dbo" };
public string Id { get; set; } = "PROFILE_GUID";
public string Active { get; set; } = "ACTIVE";
public string TypeId { get; set; } = "TYPE_ID";
public string Type { get; set; } = "TYPE";
public string Mandantor { get; set; } = "MANDANTOR";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string Description { get; set; } = "DESCRIPTION";
public string LogLevelId { get; set; } = "LOG_LEVEL_ID";
public string LogLevel { get; set; } = "LOG_LEVEL";
public string LanguageId { get; set; } = "LANGUAGE_ID";
public string Language { get; set; } = "LANGUAGE";
public string AddedWho { get; set; } = "ADDED_WHO";
public string AddedWhen { get; set; } = "ADDED_WHEN";
public string ChangedWho { get; set; } = "CHANGED_WHO";
public string ChangedWhen { get; set; } = "CHANGED_WHEN";
public string FirstRun { get; set; } = "FIRST_RUN";
public string LastRun { get; set; } = "LAST_RUN";
public string LastResult { get; set; } = "LAST_RESULT";
}

View File

@@ -1,40 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class RecActionViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_ACTION", Schema = "dbo" };
public string Id { get; set; } = "ACTION_GUID";
public string ProfileId { get; set; } = "PROFILE_ID";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string ProfileType { get; set; } = "PROFILE_TYPE_ID";
public string Sequence { get; set; } = "SEQUENCE";
public string EndpointId { get; set; } = "ENDPOINT_ID";
public string EndpointUri { get; set; } = "ENDPOINT_URI";
public string EndpointAuthId { get; set; } = "ENDPOINT_AUTH_ID";
public string EndpointAuthType { get; set; } = "ENDPOINT_AUTH_TYPE_ID";
public string EndpointAuthTypeName { get; set; } = "ENDPOINT_AUTH_TYPE";
public string EndpointAuthApiKey { get; set; } = "ENDPOINT_AUTH_API_KEY";
public string EndpointAuthApiValue { get; set; } = "ENDPOINT_AUTH_API_VALUE";
public string EndpointAuthApiKeyAddTo { get; set; } = "ENDPOINT_AUTH_API_KEY_ADD_TO_ID";
public string EndpointAuthApiKeyAddToName { get; set; } = "ENDPOINT_AUTH_API_KEY_ADD_TO";
public string EndpointAuthToken { get; set; } = "ENDPOINT_AUTH_TOKEN";
public string EndpointAuthUsername { get; set; } = "ENDPOINT_AUTH_USERNAME";
public string EndpointAuthPassword { get; set; } = "ENDPOINT_AUTH_PASSWORD";
public string EndpointAuthDomain { get; set; } = "ENDPOINT_AUTH_DOMAIN";
public string EndpointAuthWorkstation { get; set; } = "ENDPOINT_AUTH_WORKSTATION";
public string EndpointParamsId { get; set; } = "ENDPOINT_PARAMS_ID";
public string SqlConnectionId { get; set; } = "SQL_CONNECTION_ID";
public string SqlConnectionServer { get; set; } = "SQL_CONNECTION_SERVER";
public string SqlConnectionDb { get; set; } = "SQL_CONNECTION_DB";
public string SqlConnectionUsername { get; set; } = "SQL_CONNECTION_USERNAME";
public string SqlConnectionPassword { get; set; } = "SQL_CONNECTION_PASSWORD";
public string RestType { get; set; } = "REST_TYPE_ID";
public string RestTypeName { get; set; } = "REST_TYPE";
public string PreprocessingQuery { get; set; } = "PREPROCESSING_QUERY";
public string HeaderQuery { get; set; } = "HEADER_QUERY";
public string BodyQuery { get; set; } = "BODY_QUERY";
public string PostprocessingQuery { get; set; } = "POSTPROCESSING_QUERY";
public string ErrorAction { get; set; } = "ERROR_ACTION_ID";
public string ErrorActionName { get; set; } = "ERROR_ACTION";
}

View File

@@ -1,23 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class ResultViewOptions
{
public ViewOptions View { get; set; } = new() { Name = "VWREC_RESULT", Schema = "dbo" };
public string Id { get; set; } = "RESULT_GUID";
public string ActionId { get; set; } = "ACTION_ID";
public string ProfileId { get; set; } = "PROFILE_ID";
public string ProfileName { get; set; } = "PROFILE_NAME";
public string StatusCode { get; set; } = "STATUS_ID";
public string StatusName { get; set; } = "STATUS";
public string Type { get; set; } = "RESULT_TYPE_ID";
public string TypeName { get; set; } = "RESULT_TYPE";
public string Header { get; set; } = "RESULT_HEADER";
public string Body { get; set; } = "RESULT_BODY";
public string Info { get; set; } = "RESULT_INFO";
public string Error { get; set; } = "RESULT_ERROR";
public string AddedWho { get; set; } = "ADDED_WHO";
public string AddedWhen { get; set; } = "ADDED_WHEN";
public string ChangedWho { get; set; } = "CHANGED_WHO";
public string ChangedWhen { get; set; } = "CHANGED_WHEN";
}

View File

@@ -1,8 +0,0 @@
namespace ReC.Application.Common.Options.DbModel;
public class ViewOptions
{
public string Name { get; set; } = null!;
public string Schema { get; set; } = "dbo";
}