I don't want to have to add each mapping class manually to the ModelBuilder() so was trying to use my limited knowledge of reflection to register them. This is what I have, and this is the error I am getting:
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 The type arguments for method 'System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar.Add(System.Data.Entity.ModelConfiguration.EntityTypeConfiguration)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\root\development\playground\PostHopeProject\PostHope.Infrastructure.DataAccess\DatabaseFactory.cs 67 17 PostHope.Infrastructure.DataAccess