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">
<DefiningQuery>
SELECT EmployeeID, CAST(CASE WHEN EmployeeId IN (SELECT EmployeeManager FROM EmployeesWithManager) THEN 1 ELSE 0 END AS BIT) as IsManager
FROM EmployeesWithManager
</DefiningQuery>
</EntitySet>
<EntityType Name="EmployeeWithManagerStatus">
<Key>
<PropertyRef Name="EmployeeId" />
</Key>
<Property Name="EmployeeId" Type="int" Nullable="false" />
<Property Name="IsManager" Type="bit" />
</EntityType>
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?