IQueryable<T> does not contain a definition for 'Include' and no extension method 'Include'
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;
If you are using .Net core version then you need to install: Microsoft.EntityFrameworkCore nuget package.
And then:
using Microsoft.EntityFrameworkCore;
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.