DbSet doesn't contain definition for FirstOrDefault?

前端 未结 3 1119
攒了一身酷
攒了一身酷 2021-01-05 08:35

I recently migrated an existing project to .net 4.5 and changed out what this project was using for data access (switching to Entity Framework).

For some reason any

相关标签:
3条回答
  • 2021-01-05 09:24

    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 :)

    0 讨论(0)
  • 2021-01-05 09:25

    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>.

    0 讨论(0)
  • 2021-01-05 09:25

    This question already has an answer but I had a different cause.

    I also needed to have a reference to System before First or Default would show up...

    0 讨论(0)
提交回复
热议问题