I had one question yesterday on the worst DataBase I have ever seen.
Imagine two tables:
- T1 with three columns:
- Id (PK)
- T2 with three columns:
- Id (PK)
And what they wanted to do is to add a relationship between T1 and T2 with T1FK1 = T2FK1 AND T1FK2 = T2FK2 using Entity Framework.
I first thought that it’s a very strange way to do a relationship many to many but in fact, it’s worst! The relationship they wanted is one to many from T1 to T2! (It should be probably too easy to add a T1Id column in T2 table. No comment).
Likely, Entity Framework is the friend of the developer and it is possible to do this scenario. How?
This is what I did:
I added an ssdl view:
<EntitySet Name=“T1T2RelationShip“ EntityType=“TestLaFourmiRougeModel1.Store.T1T2RelationShipEntityType“>
SELECT T1.Id AS T1ID, T2.ID AS T2ID
FROM T1 INNER JOIN T2 ON T1.FK1 = T2.FK1 AND T1.FK2 = T2.FK2
<PropertyRef Name=“T2ID“ />
<Property Name=“T1ID“ Type=“int“ />
<Property Name=“T2ID“ Type=“int“ Nullable=“false“ />
Then, I added a relationship 0..1 -> many between T1 and T2 and I mapped it on my SSDL View.
That’s all, folks! [:)] Entity Framework is so good! [:D]
However, in this case, I think they really should change their DB (and probably also their DBA)…