This question is pretty much a duplicate of this one except that answer is 8 years old and not working for me. Also this one, this one, and this one.
Every answer I can find to this question just says to add using Microsoft.EntityFrameworkCore;
(and the first answer linked also specifies using System.Linq;
.) I have installed Microsoft.EntityFrameworkCore
8.0.10 as well as Microsoft.EntityFrameworkCore.SqlServer
8.0.10 through nuget, and have added both using statements.
To ensure there wasn't any other using
conflicting, I even tried removing all using statements other than the 2 specified, and Include was still not found. I also tried some other random ones, like Microsoft.Data.Sql
or Microsoft.EntityFrameworkCore.SqlServer
.
I have also tried reinstalling both packages through nuget, cleaning/rebuilding the solution, and restarting Visual Studio multiple times.
Obviously I am also using .NET Core 8.
'IQueryable' does not contain a definition for 'Include' and no accessible extension method 'Include' accepting a first argument of type 'IQueryable' could be found (are you missing a using directive or an assembly reference?)
Code:
using Microsoft.EntityFrameworkCore;
using System.Linq;
IQueryable queryable = GetQueryableByTableName("table1");
queryable.Include("table2");
In EF Core 8, there are no non-generic overloads of the Include method. So you'll need to have your IQueryable
be a generically-typed IQueryable<>
of some kind. If you don't know the type, it's possible you can leverage dynamic
typing to determine and invoke the right generic version of the method at run-time:
IQueryable queryable = GetQueryableByTableName("table1");
queryable = EntityFrameworkQueryableExtensions.Include((dynamic)queryable, "table2");