ssdl view and TPH

This post uses the same idea than my last one: “Entity Framework: How to use Entity Splitting with different PK?”.

We have a table Employee with 3 columns: EmployeeId (PK), EmployeeName and EmployeeManager (FK to EmployeeId).

In my EDM, I want 2 entity types: Employee and Manager which inherits Employee.

How to do this?

The idea is to use a ssdl view to use TPH.

I just need to add this code in ssdl:

<EntitySet Name=EmployeeWithManagerStatus EntityType=TestModel.Store.EmployeeWithManagerStatus>


        SELECT EmployeeID, CAST(CASE WHEN EmployeeId IN (SELECT EmployeeManager FROM EmployeesWithManager) THEN 1 ELSE 0 END AS BIT) as IsManager

        FROM EmployeesWithManager



<EntityType Name=EmployeeWithManagerStatus>


        <PropertyRef Name=EmployeeId />


    <Property Name=EmployeeId Type=int Nullable=false />

    <Property Name=IsManager Type=bit />


When I do it, I just need to add a Manager entity type, add inheritance between it and Employee and then, map Manager entity type with my ssdl view. Then, I just need to add a condition on Manager entity type: “IsManager = true”.

And it’s all. Cool isn’t it?

This entry was posted in 7671, 7674, 7675. Bookmark the permalink.

2 Responses to ssdl view and TPH

  1. Vincent Grondin says:

    Hi Matthieu, I tried to do like you mentionned above but I keep having a problem with my primary key for the ssdl view… The EF designer auto generates a Key for me from my view but uses the wrong field… How can I tell the designer to use field X instead of field Y? Can you contact me via email at vgrondin on hotmail… I’d be glad to continue this with you and in french (since I think it’s your native tongue, it’s mine too)… Let’s hope you can help me out with this 🙂 Thanks for your time

  2. Matthieu MEZIL says:

    I think you don’t speak about ssdl view but about view. SSDL view aren’t defined in DB.
    With DB views, the wizard uses all the non nullable columns as key. In your case, you should open your edmx with the xml editor to change the key.

Leave a Reply

Your email address will not be published. Required fields are marked *