Entity Framework - can't generate classes after adding basic inheritance RRS feed

  • Question

  • (Using EF 5, database-first)

    Just created a new entity (by importing a table from the DB to the EFmodel) and tried to make it inherit from an old entity (by setting the BaseType property of the new entity) - this causes the entire EF-model to break, despite there being other entities which inherit the exact same way. By breaks, I mean that upon using 'Run Custom Tool' it will be unable to generete any classes from the EF-model. If I remove the inheritance it reverts back to working fine again. I've checked the XML of the edmx diagram and there are no errors generated at all... Any idea what could be going on?

    Here are some more details: Got an existing project where we've successfully set up some inheritance earlier. Let's say we already have the entities Koala and Wombat which inherit from the entity Animal. It's been a good while since we added any new entities but now it's time to add a new one called Kangaroo. I'm not very experienced with EF or databases in general, but I just follow the same simple process that I remember from before:

    • create the table in the db
    • Create the relation between animal and kangaroo by adding a the relation FK_Kangaroo_Animal between Animal.Id and Kangaroo.Id
    • open the edmx schema, do an "update model from database" and select the Kangaroo table.
    • Open up the properties for the Kanggaroo entity, and set BaseType = Animal.

    The inheritance seems to be added successfully. But upon performing the usual 'Run Custom Tool' to generate the classes from the EF-model, no classes will be generated.

    Why could this be? Could it be some rookie mistake?
    Like I said, I am a newb and it's been a while since I did this the last time, but it's worked before and I don't think I'm doing anything differently. I've double checked the DB and the EF-model to verify that Kangaroo is set up the same way as Wombat and Koala which work just fine.

    Monday, October 7, 2013 8:58 AM


  • Hello,

    Thanks for posting your question to this forum.

    If I understand correctly, you want to know how to add an inheritance with Entity Framework using database first.

    From your description, I am a bit confused about that how the 'Run Custom Tool' will generate classes from the EF-model. As far as I know, if we want to create an inheritance in entity framework using database first, we need to do steps as follow:

    1. Create a new entity named Kangaroo that has the base type Animal.
    2. Cut the properties that Kangaroo needs from the Animal to the Kangaroo.
    3. Right-click the Kangaroo and select Table Mapping.
      1. Click <Add a Table or View> in the Mapping Details window.
      2. The <Add a Table or View> field becomes a drop-down list of tables or views to which the selected entity can be mapped.
      3. Select Animal from the drop-down list.
      4. The Mapping Details window is updated with default column mappings and an option for adding a condition.
      5. Click on <Add a Condition>.
      6. The <Add a Condition> field becomes a drop-down list of columns for which conditions can be set.
      7. Select Discriminator (a column used to be judge which row belongs to which entity) from the drop-down list.
      8. In the Operator column of the Mapping Details window, select = from the drop-down list.

    In the Value/Property column, type Instructor. The end result should look like this:

    For more detail information, there is a link that shows a walkthrough.

    If this does not work for you, please let me know.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Monday, October 14, 2013 8:58 AM
    Tuesday, October 8, 2013 3:53 AM