IQueryable does not contain a definition for 'Include' and no extension method 'Include'

后端 未结 6 1889
离开以前
离开以前 2020-12-13 23:32

I\'m trying to use Include extension on IQueryable set, but I have the following issue:

Error 1 \'System.Linq.IQueryable<.Model.InsuranceCaseType

相关标签:
6条回答
  • 2020-12-14 00:11

    If you are using .Net core version then you need to install: Microsoft.EntityFrameworkCore nuget package.

    And then:

    using Microsoft.EntityFrameworkCore;
    
    0 讨论(0)
  • 2020-12-14 00:11

    If you're looking for the method Jon is talking about, you'll need to import the following namespace:

    using System.Data.Entity.QueryableExtensions
    

    MSDN Link

    0 讨论(0)
  • 2020-12-14 00:13

    Include is not an extension method on Queryable, so it doesn't come together with all the usual LINQ methods. If you are using Entity Framework, you need to import the corresponding namespace:

    using System.Data.Entity;
    
    0 讨论(0)
  • 2020-12-14 00:30

    Some further help for others experiencing this issue even after including the using directive. Jon mentioned it but I just want to make it clear as even after reading the answer I was stuck for a while, sorry if it seems obvious but might save someone else some time.

    The issue for me was the reference, which was Entity Framework. After using Nuget to install EF the .Include() worked as usual.

    This threw me because the same code with the .Include() was working in my main project (MVC app) but wasn't working in a different project in the same solution, even with the using, as it was missing EF. Hope this saves someone else some time.

    0 讨论(0)
  • 2020-12-14 00:32

    If you deploy directly to your repository, you can use Include(), as per example code below:

    public IQueryable<Colaborador> FindAll()
    {
         var retRepository = from colaborador in All()
                                .Include(x => x.Cliente)
                                select colaborador;
    
         return retRepository;
    }
    
    0 讨论(0)
  • 2020-12-14 00:34

    (I am using EF 7 with ASP.NET 5 Preview, DNX 5.0 Framework)

    Adding this solved mine -

    using Microsoft.Data.Entity;

    Note: It's not System.Data.Entity

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