title: Entity Framework oddity - one column is wrong
body: <p>First off, I already have a workaround, plus the database this is happening on is being replaced (completely new db / schema + new app)</p>
  
  <p>That being said, I'd like to understand WHY this happened so I don't run into it again. Thoughts are appreciated.</p>
  
  <p>Anyways: take this simple line of code:</p>
  
  <pre><code>var privs = _olddb.tbl_Privileges.Where(x =&gt; x.UserID == userFrom);
  </code></pre>
  
  <p>Simple enough. Basically, an example of the data coming out should be:</p>
  
  <pre><code>+--------+----------+------------+----------------+------------+
  | UserID | RegionID | FacilityID | InitiativeType | AccessType |
  +--------+----------+------------+----------------+------------+
  |    290 |       27 |        123 | C              | F          |
  |    290 |       27 |        123 | P              | F          |
  |    290 |       27 |        124 | C              | F          |
  |    290 |       27 |        124 | P              | F          |
  +--------+----------+------------+----------------+------------+
  </code></pre>
  
  <p>Instead though... I get this:</p>
  
  <pre><code>+--------+----------+------------+----------------+------------+
  | UserID | RegionID | FacilityID | InitiativeType | AccessType |
  +--------+----------+------------+----------------+------------+
  |    290 |       27 |        123 | P              | F          |
  |    290 |       27 |        123 | P              | F          |
  |    290 |       27 |        124 | P              | F          |
  |    290 |       27 |        124 | P              | F          |
  +--------+----------+------------+----------------+------------+
  </code></pre>
  
  <p>Note the <code>InitiativeType</code> column....</p>
  
  <p>However, if I run this command:</p>
  
  <pre><code>var privs =_olddb.Database.SqlQuery&lt;tbl_Privileges&gt;("SELECT * FROM tbl_Privileges WHERE UserID = " + userFrom);
  </code></pre>
  
  <p>Then I get the correct output.</p>
  
  <p>What gives?</p>
  
  <p>-EDIT- Regarding answer provided by marc_s
  (Keep in mind, I had no hand in making the original db, and I'm afraid to modify it, it's in use by a very old web app..)
  I honestly feel silly for not having checked the PK's before posting, my apologies.  I checked the database, that table has no PK's defined at all.  So I checked the edmx in EF, and found only RegionID and FacilityID were set a Entity Keys:</p>
  
  <p><a href="https://i.stack.imgur.com/LNF9a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LNF9a.png" alt="enter image description here"></a></p>
  
  <p>So I updated the edmx model and set all fields as keys (since I can have 4 fields the same easily between two privilege sets, as Access Type has multiple values as well), ran the script again, and this time it worked perfectly with the Linq statement.</p>