EntityFramework 自动添加 EntityTypeConfiguration
使用程序集反射的方法。
var typesToRegister = Assembly.GetExecutingAssembly().GetTypes(). Where(type => !String.IsNullOrEmpty(type.Namespace)). Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>)); foreach (var type in typesToRegister) { dynamic configurationInstance = Activator.CreateInstance(type); modelBuilder.Configurations.Add(configurationInstance); }
Categories:
.net
Tags:
代码
, Entity Framework
已禁用评论。