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());
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);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.