title: Linq - Select record from database by id
body: <p>I'm trying to get a record from the database with an id I specified. However I'm having difficulties creating the correct Linq query.<br>
  First off this is two of the things I've tried, but which don't seem to work.  </p>
  
  <pre><code>var query_result = from d in db.Departments
                     where d.id == id
                     select d;
  </code></pre>
  
  <p>Here I try to select the department which follows my given id. However in my <code>Department</code> class the <code>id</code> attribute is private. Which I would like to keep that way, in compliance with normal OOP.  </p>
  
  <p>Before that I tried doing this:  </p>
  
  <pre><code>var query_result = from d in db.Departments
                     where d.getId() == id
                     select d;
  </code></pre>
  
  <p>In this case I'm using the getter for the id, but that gives me the following error:  </p>
  
  <blockquote>
    <p>Method 'Int32 getId()' has no supported translation to SQL.  </p>
  </blockquote>
  
  <p>I've tried looking around but I can't seem to find a conclusive answer for something that should be, in my opinion, very simple. I do see a lot of examples access the class attributes directly, but that would mean making them public. Unless I'm missing something I wouldn't really want to go that way.</p>
  
  <p>I'm not very experienced in Linq (or c# for that matter). Thanks in advance.</p>