title: Selecting User from a table with LINQ statements/expression
body: <p>Im new to C#, Entity Framework and LINW hope there is someone who can explain something in the code about LINQ. I have a method inside my program that select a user from the table. That method is:</p>
  
  <pre><code> public static cp_user SelectUser(string user, string passw)
      {
          try
          {
              cp_user entityUser = (from u in _db.cp_user
                                    where u.username == user &amp;&amp; u.password == passw
                                    select u).FirstOrDefault();
  
              return entityUser;
          }
          catch (System.Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
  
          return null;
      }
  </code></pre>
  
  <p>cp_user is the class corresponding to the table I have in my database. And _db is a field which holds a reference to the database instance.</p>
  
  <p>In the select user method I understand that there is a creation of local variable of type cp_user and it is defined by the statement: </p>
  
  <pre><code> (from u in _db.cp_user
                                where u.username == user &amp;&amp; u.password == passw
                                select u).FirstOrDefault();
  </code></pre>
  
  <ol>
  <li><p>Im confused about the first part of the statement. "From u in _dp.cp_user". 
  Ive been working with MySQL so far, so its confusing to see this "from u". In MySQL this "u" would be referring to a table. But in Linq im confused to what it does.</p></li>
  <li><p>I do understand roughly the rest of the statement though, that the username and password arguments in the method must be equal to data that is in the table. And that it will return the database object. But again confused about the u, in the last part saying "select u".</p></li>
  </ol>
  
  <p>Another question I have is in another method called checkany, which check if the user log in is correct:</p>
  
  <pre><code> public static bool CheckAny(string user, string passw)
      {
          bool itIsAlredy = _db.cp_user.Any(u =&gt; u.username == user &amp;&amp; u.password == passw);
          return itIsAlredy;
      }
  </code></pre>
  
  <p>I understand that the CheckAny methodtakes in username and password and creates a boolean variable which can either return true or false depending on the statement. Here is the part I dont understand.</p>
  
  <ol start="3">
  <li>For me this statement "(u => u.username == user &amp;&amp; u.password == passw);" looks like it means that the username and password in the method parameters must be existent in the database. But someone at school told me that it means that both username and password must be corresponding correctly meaning; you can't have a password thats connected to another username. So what does this statement actually say. And also again I don't understand the whole "u => u.username". Like what does this u represent. Is it special linq syntax if so what does it mean? Anyone has links that explain this?</li>
  </ol>
  
  <p>Im very sorry if I have made any wrongly statements please correct me if I have im new to programming in general only worked with MySQL before. If anyone could answer the 3 questions I have would be greatly appreciated.</p>
  
  <p>Thanks in advance</p>