pat wrote:
Ah thanks I'm aware that there is an attribute but since the model is used in a .NET 3.5 & .NET 4.6.2 context we can't use an attribute that was introduced in .NET 4.5.
So the only way to do it would be to it add it to the data context in CodeFirst.
The only overwrite I can find is DataContext.OnContextCreated though which gets called after the context is already created. So it looks like I would need another extensibility method in the template so I can define the ignore's in a partial class.
modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty);
Thanks!
No, there's an easier way, simply create a derived class from the Context and ModelBuilder classes: in the derived class of the ModelBuilder, you override each mapping method for an entity and first call the base' version and then make your changes to the EntityTypeBuilder<T> object passed in.
In the derived class of the Context class, override OnModelCreating and do:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
new YourModelBuilderDerivedClass().BuildModel(modelBuilder);
}
where YourModelBuilderDerivedClass is your modelbuilder subclass.