title: linq mvc foreign key value
body: <p>I am new to MVC. and I'm trying to find my way through online tutorials.</p>
  
  <p>being said that,</p>
  
  <p>I have a table A (a1,a2,a_b1)
  and a table B (b1,b2)</p>
  
  <p>and a_b1 is a foreign key from B.b1.</p>
  
  <p>I generated the List view in Visual studio, using its template.
  I have access to a1, and a2 fields of table A.
      <code>&lt;%=Html.Encode(item.a1) %&gt;</code>  and <code>&lt;%=Html.Encode(item.a2) %&gt;</code></p>
  
  <p>but when I try to access the A.a_b1 value (NOT the reference to table B), I only get the reference to an object from table B.
  Thanks Kirill 
  I don't know what are  CodeFirst, ModelFirst or DatabaseFirst.
  I have these tables, and used visual studio, and Linq to generate the class for tables A and B.
  so A.a1, A.a2 show up in the object created.
  and I have A.B, and A.BReference in the fields</p>
  
  <p>I think there should be a way to access the value of the column not the reference. 
  Can you please help me?</p>
  
  <p>I don't want to perform the join, just need the value.</p>
  
  <p>I tried my best to be specific but please let me know if this is not clear. </p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>I used ADO.Net Entity Data Model to generate objects associated with my tables.</p>
  
  <p>In my controller I have :</p>
  
  <pre><code>A sample1=repository.search(id);
  string s1 = sample1.a1;
  string s2 = sample1.a2;
  string s3 = sample1.a_b1; (ERROR)
  </code></pre>
  
  <p>Instead I have</p>
  
  <pre><code>   sample1.B   (an object of type B)
  and 
  sample1.BReference  (object of type EntityReference&lt;B&gt;)
  </code></pre>