Add EnsureEntity<T> method to DbModelOptions
Introduce EnsureEntity<T>(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.
This commit is contained in:
@@ -7,4 +7,17 @@ public record DbModelOptions
|
|||||||
public Dictionary<string, EntityOptions> Entities { get; init; } = [];
|
public Dictionary<string, EntityOptions> Entities { get; init; } = [];
|
||||||
|
|
||||||
public Dictionary<string, VirtualEntityOptions> VirtualEntities { get; init; } = [];
|
public Dictionary<string, VirtualEntityOptions> VirtualEntities { get; init; } = [];
|
||||||
|
|
||||||
|
public void EnsureEntity<T>(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<T>();
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException($"Entity options for type '{typeof(T).FullName}' not found.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user