1

I have an existing SQL Server database using Entity Framework code-first with a table-per-hierarchy option.

This means there is a Discriminator column in table Persons representing the different possible types - let's say "Doctor" and "Nurse".

Now, I want to move over to managing the database in a Visual Studio Database Project (SSDT). And at the same time generate the pocos from the database, to still use Entity Framework (except for the migration part).

I have tried the Entity Framework Reverse POCO Generator which seems quite alright. But it only generates a Person.cs file - no Doctor.cs (Doctor : Person) or Nurse.cs (Nurse : Person).

So a class hierarchy is not created from the Person table via the discriminator column.

Questions:

  • Is there a way to configure table-per-hierarchy for Entity Framework Reverse POCO Generator?
  • If no, is there another Entity Framework tool that can achieve it?
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    I really prefer to use the Code First approach with EF for both existing and new databases. In my experience it's the most flexible. It's not dependent on buggy designers. And it allows me to focus most on the object model. If your legacy db has tons of tables in it Code First may be too time consuming. There are a lot of great tutorials available for it, e.g: https://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph – ssis_ssiSucks Jul 05 '17 at 16:21
  • Did you ever find a solution for this? – MikeS Jul 12 '19 at 17:18
  • No, I believe it is seen as an anti pattern to make code-first with class hierachies which are then reflected in the database. Its hard to make a database first doing the same. – Christian Holm Jørgensen Jul 13 '19 at 18:37

0 Answers0