DbSet doesn't contain definition for FirstOrDefault?

前端 未结 3 1151
攒了一身酷
攒了一身酷 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: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 class which does not implement IQueryable or IEnumerable.

提交回复
热议问题