I do not want each mapping class to be manually added to ModelBuilder (), so I tried to use my limited reflection knowledge to register them. This is what I have, and this is the error I get:
CODE:
private static ModelBuilder CreateBuilder() {
var contextBuilder = new ModelBuilder();
IEnumerable<Type> configurationTypes = typeof(DatabaseFactory)
.Assembly
.GetTypes()
.Where(type => type.IsPublic && type.IsClass && !type.IsAbstract && !type.IsGenericType && typeof(EntityTypeConfiguration).IsAssignableFrom(type) && (type.GetConstructor(Type.EmptyTypes) != null));
foreach (var configuration in configurationTypes.Select(type => (EntityTypeConfiguration)Activator.CreateInstance(type)))
{
contextBuilder.Configurations.Add(configuration);
}
return contextBuilder;
}
Error:
Error 2 Type arguments for the method "System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar.Add (System.Data.Entity.ModelConfiguration.EntityTypeConfiguration)" cannot be taken out of use. Try explicitly specifying type arguments. C: \ root \ development \ playground \ PostHopeProject \ PostHope.Infrastructure.DataAccess \ DatabaseFactory.cs 67 17 PostHope.Infrastructure.DataAccess