Question

I'm trying to kick off a project needing table-per-hierachy. I've done this in the past with NHibernate, but we want to avoid having to hand edit XML mapping files - so are trying to use Entity Framework and it's Designer.

I've been following this example online: http://mosesofegypt.net/post/Inheritance-and-Associations-with-Entity-Framework-Part-1.aspx

When trying to select a Table from the "<Add Table or View>" dropdown, I can't select any tables, instead the list shows "(Empty)".

failing hard

The only deviation I've made from the tutorial is that I didn't generate the Person table off the sample database, as far as I can tell this shouldn't make a difference (we want to generate the DB off the model, not vice versa).

Not sure what criteria a table needs to meet to be eligible to add a discriminator to...

Was it helpful?

Solution

If you need to generate DB from the model you cannot see any table in mapping because both mapping and information about tables is generated when you generate the database. EDMX has quite complex structure (much more complex than very easy hbm files for NHibernate). The complexity is even worse because EDMX doesn't have anything implicit - everything must be described and it must be described three times.

EDMX consists of three parts:

  • CSDL - conceptual model you see in the designer (classes)
  • SSDL - database description - this can be browsed in model browser but it is read-only
  • MSL - mapping between SSDL and MSL (that is what you are trying to edit in that window).

When you are going to use model-first (draw entities in designer and generate database) you define only CSDL and everything else is generated with SQL for the database. You will also probably need another template / workflow for DB generation because I guess it will by default use Table-per-type inheritance. Check Database generation power pack - it should contain template for TPH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top