I have the following model.
interface IKeywordedEntity
{
IEntityCollection<Keyword> Keywords { get; }
}
class Foo : EntityBase, IKeywordedEntity
{
public virtual IEntityCollection<Keyword> Keywords { get { ... } }
}
class Bar : EntityBase, IKeywordedEntity
{
public virtual IEntityCollection<Keyword> Keywords { get { ... } }
}
I want to write an extension method that takes care of the keywords automatically for each of these in OnModelCreating
.
public static void WithKeywords<TEntityType>(this EntityTypeConfiguration<TEntityType>
entityTypeConfiguration) where TEntityType : EntityBase, IKeywordedEntity
{
entityTypeConfiguration.HasMany(e => e.Keywords).WithMany();
}
So I invoke it like this in OnModelCreating
.
modelBuilder.Entity<Foo>.WithKeywords();
modelBuilder.Entity<Bar>.WithKeywords();
However, I get the following exception:
The navigation property 'Keywords' is not a declared property on type 'Foo'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.
What can I do to allow this extension method to work?