Automatically turn navigation AutoInclude on when 'Scaffolding' context?

Viewed 23

Is there an option to make this automatically? Because I have a database first situation and when I 'Scaffold' my tables the context is setup without this naviagtion. What I do is I put it manually like this :

entity.Navigation(x => x.Cards).AutoInclude();

But I'm afraid that this will be overwritten every time a new 'Scaffold' is done to add new tables.

The entity :

public partial class Contract
{
    public Contract()
    {
        Cards = new HashSet<Card>();
    }
    
    // ...

    public virtual ICollection<Cards> Cards { get; set; }
}
1 Answers

You can implement the partial method OnModelCreatingPartial in a partial class so nothing will be overwritten.

Related