Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

linq

I'm trying to use Include extension on IQueryable 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 the 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; 
like image 949
Egor Avatar asked Nov 16 '13 10:11

Egor


People also ask

What does IQueryable include do?

Include(IQueryable, String)Specifies the related objects to include in the query results.

Does IQueryable implement IEnumerable?

The IQueryable interface inherits the IEnumerable interface so that if it represents a query, the results of that query can be enumerated. Enumeration causes the expression tree associated with an IQueryable object to be executed.

Is IQueryable a collection?

Both IEnumerable and IQueryable are forward collection. Querying data from a database, IEnumerable execute a select query on the server side, load data in-memory on a client-side and then filter data.

What is IQueryable return?

IQueryable is executed. // // Returns: // A System.Type that represents the type of the element(s) that are returned when. // the expression tree associated with this object is executed.


2 Answers

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; 
like image 60
Jon Avatar answered Sep 16 '22 23:09

Jon


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

And then:

using Microsoft.EntityFrameworkCore; 
like image 41
charino Avatar answered Sep 19 '22 23:09

charino