DbSet doesn't contain definition for FirstOrDefault?

The assembly for Queryable (the thing that adds the FirstOrDefault extension method you are using) is in System.Core, however it's namespace is System.Linq, you can see this on the MSDN page for it

Namespace: System.Linq
Assembly: System.Core (in System.Core.dll)

You need to have in your project a refrence to System.Core and in the file you are trying to use it a using System.Linq;

If you have both of these things double check that your project or some project you are refrencing did not create it's own System.Data.Entity.DbSet<T> class which does not implement IQueryable<T> or IEnumerable<T>.


I was having the same problem. I tried the following solution to solve the problem

  • Right click on the project.
  • Click on "Property Pages".
  • Go to the "Build" tab.
  • Set to "Target Framework" 4.5.
  • Try "Build"

I hope this is resolved :)