Add an overload of DbModelBuilder.Configurations.AddFromAssembly() that accepts a namespace parameter
See original GitHub issueDbModelBuilder.Configurations.AddFromAssembly()
adds all EntityTypeConfiguration<TEntityType>
classes from the DbContext’s assembly.
There may be assemblies containing multiple DbContext
types, each requiring just a selection of the configuration types in the assembly. These configuration must therefore be added individually, which is easy to forget when a new entity class is introduced.
It would be very convenient to have an overload DbModelBuilder.Configurations.AddFromAssembly(namespaceName)
.
Or, more flexible, as proposed below:
DbModelBuilder.Configurations.AddFromAssembly(Assembly assembly, Func<Type,bool> filter)
Since DbModelBuilder.Configurations.Add
requires a generic type instance it’s hard (or undoable) to do this by reflection because the object created by Activator
doesn’t have the correct type at compile time. It requires internal EF code to solve this problem as developer.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
@GertArnold I created a few extension methods using reflection to get all model types, or
EntityTypeConfiguration
orComplexTypeConfiguration
from an assembly, and add them toDbModelBuilder
; I had an optionalFunc<Type,bool> filter
to allow custom filtering, and a couple of overloads that used stringrootNameSpace
to include orIEnumerable<Type>
to exclude unwanted types. I would have to remove some custom dependencies but I could probably publish them if it would help you out. To my mind, an overload ofDbModelBuilder.Configurations.AddFromAssembly(Assembly assembly, Func<Type,bool> filter)
would be the most useful to add to the core code.This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.