title: Entity Framework, T4 templates, and how to find out if a property has a 1-1 mapping table collapsed
body: <p>I am using EF5 as my ORM tool. I have a relationship between 3 tables in the DB as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/MF4RZ.jpg" alt="DB Model"></p>
  
  <p>Table 1 is the main table. It has a "1 to 0..1" relationship to Table 2. Table 2 has a "many to 1" relationship to Table 3.</p>
  
  <p>Now when you import this into EF, it collapses (hides) Table 2. You get to Table 3 by doing something like:</p>
  
  <pre><code>Table1.Table3
  </code></pre>
  
  <p>Basically in my T4 template for generating code, I need to know if the relationship between Table 1 and Table 3 is hiding a middle table. </p>
  
  <p>How can I do this? </p>
  
  <p>It is easy for a many to many table link, as I can look at the navigation properties relationship multiplicity as follows:</p>
  
  <pre><code>if (navProperty.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &amp;&amp;
      navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
  </code></pre>
  
  <p>And I will know a table is missing inbetween, but with the model above, it becomes a many to 0..1 relationship, which may or may not be hiding a middle table.</p>
  
  <p>Any ideas?</p>