Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
992 views
in Technique[技术] by (71.8m points)

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

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...