Question

I have a pretty big EF model, and I'm trying to avoid going through each class and fishing for properties that are of type enum and setting [NotMapped] attribute on top of them. What I was hopping to is was to write smth like this

protected override void OnModelCreating(DbModelBuilder modelBuilder){
  modelBuilder.Properties<enum>().Configure(p=>p.Ignore());
  ....

or

modelBuilder.Properties().Where(p=>p.GetType().IsEnum).Configure(p=>p.Ignore());
Was it helpful?

Solution

You can ignore properties on the type configuration level, so you need start from modelBuilder.Types() and not from modelBuilder.Properties():

modelBuilder.Types().Configure(typeConfiguration =>
{
    foreach (var property in typeConfiguration.ClrType
        .GetProperties().Where(p => p.PropertyType.IsEnum))
    {
        typeConfiguration.Ignore(property);
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top