Egor Egor - 1 month ago 7
C# Question

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

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


Error 1 'System.Linq.IQueryable<.Model.InsuranceCaseType>'
does not contain a definition for 'Include' and no extension method
'Include' accepting a first argument of type
'System.Linq.IQueryable<.Model.InsuranceCaseType>' could
be found (are you missing a using directive or an assembly
reference?)


My code:

var allCaseTypes = Uow.InsuranceCaseType.GetAll().Include(a=>a.Geos);


Method
GetAll()
returns -
IQueryable<.Model.InsuranceCaseType>


I have in-scope following namespaces:

using System.Collections;
using System.Collections.Generic;
using System;
using System.Data;
using System.Linq;
using System.Data.Entity;
using System.IO;
using System.Web;
using System.Web.Mvc;

Jon Jon
Answer

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;