0
public class ProductConfiguration : EntityTypeConfiguration<Product>
{
public ProductConfiguration()
{
Property(p => p.Name).HasColumnName("ProductName");
}
}
我有一個產品配置的實體框架。我想通過反思來使用它。EntityTypeConfiguration屬性方法反射
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a =>
a.GetName().Name != "EntityFramework"))
{
var configTypes = assembly.GetTypes().Where(t =>
t.BaseType != null &&
t.BaseType.IsGenericType &&
t.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>));
foreach (var configType in configTypes)
{
if (configType.BaseType == null) continue;
??????Property(p => p.Name).HasColumnName("ProductName");
??????
}
}
}
*我想通過反射使用此* - 你的意思是,你要添加「OnModelCreating」動態配置? –
我編輯的帖子onModelCreating – barteloma