From 009bb623b529e5d6811cf7d6a44a33acb7807075 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 10 Dec 2025 14:24:45 +0100 Subject: [PATCH] Add EnsureEntity method to DbModelOptions Introduce EnsureEntity(bool isVirtual) to validate and ensure entity options exist for a given type in either Entities or VirtualEntities. Throws an exception if options are missing. --- src/ReC.Infrastructure/Options/DbModelOptions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ReC.Infrastructure/Options/DbModelOptions.cs b/src/ReC.Infrastructure/Options/DbModelOptions.cs index 611b0b5..4cde16a 100644 --- a/src/ReC.Infrastructure/Options/DbModelOptions.cs +++ b/src/ReC.Infrastructure/Options/DbModelOptions.cs @@ -7,4 +7,17 @@ public record DbModelOptions public Dictionary Entities { get; init; } = []; public Dictionary VirtualEntities { get; init; } = []; + + public void EnsureEntity(bool isVirtual) + { + + var cluster = isVirtual + ? VirtualEntities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions) + : Entities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions); + + if(cluster.TryGetValue(nameof(T), out var entityOptions)) + entityOptions.EnsureProperties(); + else + throw new InvalidOperationException($"Entity options for type '{typeof(T).FullName}' not found."); + } }