Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Inheritance for navigation only

$
0
0

Hi atnoslen,

EF allows you to create un-mapped base types that are not part of the model and hence not reflected in the database. Taking your example above and using Code First to do the mapping the Person class can become an un-mapped base type. This means that there will be mappings to only two tables in the database--Users and Tickets--and Users will not contain a discriminator column.

There are some restrictions when doing this:

  • You need to use either Code First or manually edit the EDMX file. The EF designer does not support un-mapped base types at this time.
  • You cannot have navigation properties that point to or come from the base type. This is because EF then needs to reason about the type in the model and to do that it must be a part of the model, which in turn means it must be mapped. So your example above is fine because only User and Ticket reference each other. If Person were to reference some other type in the model, or some other type in the model referenced Person then it would need to be mapped.
  • You cannot declare that the base type is an entity type. In other words, using your example, do not call modelBuilder.Entity<Person>() or declare a DbSet<Person> property on your context.

Thanks,
Arthur


Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>