using Microsoft.EntityFrameworkCore; namespace HopFrame.Core.Config; public class DbContextConfig { public Type ContextType { get; } public List Tables { get; } = new(); public DbContextConfig(Type context) { ContextType = context; foreach (var property in ContextType.GetProperties()) { if (!property.PropertyType.IsGenericType) continue; var innerType = property.PropertyType.GenericTypeArguments.First(); var setType = typeof(DbSet<>).MakeGenericType(innerType); if (property.PropertyType != setType) continue; var table = new TableConfig(this, innerType, property.Name, Tables.Count); Tables.Add(table); } } } public class DbContextConfig(DbContextConfig config) { public DbContextConfig InnerConfig { get; } = config; public DbContextConfig Table(Action> configurator) where TModel : class { var table = Table(); configurator.Invoke(table); return this; } public TableConfig Table() where TModel : class { var table = InnerConfig.Tables.Single(table => table.TableType == typeof(TModel)); return new TableConfig(table); } }