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;
If you are using .Net core version then you need to install: Microsoft.EntityFrameworkCore nuget package.
And then:
If you're looking for the method Jon is talking about, you'll need to import the following namespace:
MSDN Link
If you deploy directly to your repository, you can use
Include()
, as per example code below:Include
is not an extension method onQueryable
, 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: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 theusing
, as it was missing EF. Hope this saves someone else some time.(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