3

Is there an easy solution for the following situation: I've got an Entity Dossier which is shared in 2 DbContexts. Dossier has 2 navigation properties, DossierType and DossierAttachment

Dossier

Dossier --> DossierType (Navigation Property)

Dossier --> DossierAttachment (Navigation Property)

I want to exclude the DossierType Entity in DbContext1. I do not want it to be savable to database, navigation properties should not be set.

I was expecting that calling

modelBuilder.Ignore<DossierType>(); 

in the DbContext1.OnModelCreating would be sufficient. It should make sure that my navigation property DossierType was not 'taken into context'. It however gives following exception:

The navigation property 'DossierType' is not a declared property on type 'Dossier'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.

This exception will keep coming unless I call the Ignore on the navigation property explicitly, which I do not want. (My reallife scenario has a lot more navigation properties, I do not want to iterate these)

modelBuilder.Entity<Dossier>().Ignore(x => x.DossierType);

Is there any easy way to ignore specific entity types in an easy straight forward manner? Or should I really go for a reflection way: declaring a list of types which I don't want and ignore them using reflection?

Community
  • 1
  • 1
Ben Thaens
  • 213
  • 3
  • 9

0 Answers0