Use the configuration depending on the selected database provider #13

Merged
Wesser merged 33 commits from feat/database-persistence into feat/add-setup 2024-06-01 05:45:18 +03:00
Showing only changes of commit 7c79f7d840 - Show all commits

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace Mirea.Api.DataAccess.Persistence.Common;
public static class ModelBuilderExtensions
{
public static void ApplyConfiguration(this ModelBuilder modelBuilder, object configuration)
{
var applyGenericMethod = typeof(ModelBuilder)
.GetMethods()
.First(m => m.Name == "ApplyConfiguration" &&
m.GetParameters().Any(p => p.ParameterType.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)));
var entityType = configuration.GetType().GetInterfaces()
.First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>))
.GetGenericArguments()[0];
var applyConcreteMethod = applyGenericMethod.MakeGenericMethod(entityType);
applyConcreteMethod.Invoke(modelBuilder, [configuration]);
}
}