title: Non-Static method requires a target?
body: <p>I have never seen this error before and its very confusing, I am essentially trying to do something where I say find me all locations (will only return one) that match the location name passed in and the type:</p>
  
  <pre><code>string name = columns[40];
  Location type = db.Locations.Where(l =&gt; l.name == name).FirstOrDefault();
  Location loc = db.Locations.Where(l =&gt; l.name == name &amp;&amp; l.type == type.type).FirstOrDefault();
  </code></pre>
  
  <p>There's probably a better way to do what I want in one fell swoop, but essentially I get the name from a column (this comes from a csv file), and then say, get me that locations information. After this I say ok now that I have all that jazz, go get me a location with this name and its type.</p>
  
  <p>But I get the error:</p>
  
  <p>Non-Static method requires a target</p>
  
  <p>The top level method all this code runs in is:</p>
  
  <pre><code>static void Main(string[] args){}
  </code></pre>
  
  <p>Essentially its just a console app. So whats going on?</p>
  
  <ul>
  <li><strong>db</strong> is the context class, this should be obvious.</li>
  <li><strong>columns</strong> is me pulling the data from the csv file, in this case columns[40] would be something like "New York"</li>
  </ul>
  
  <p><strong>Full Error message from the stack trace:</strong> {"Non-static method requires a target."}</p>
  
  <p><strong>Note:</strong> The question posted as a "possible answer" does not help in this case as the main method I am running this code in is static.</p>
  
  <p>Upon further investigation I found the name and type were null so I did the following fix:</p>
  
  <pre><code>if (name != null)
  {
      Location type = db.Locations.Where(l =&gt; l.name == name).FirstOrDefault();
      Location loc = db.Locations.Where(l =&gt; l.name == name &amp;&amp; l.type == type.type).FirstOrDefault();
      locationNearbyId = loc.id;
  
      // More code
  }
  </code></pre>
  
  <p>Alas I still get the error at: <code>Location loc = db.Locations.Where(l =&gt; l.name == name &amp;&amp; l.type == type.type).FirstOrDefault();</code></p>