Jonathan Wood
Jonathan Wood

Reputation: 67195

Errors Working with Entity Framework Queries

Can anyone tell me why the following code doesn't work?

IQueryable query = from pr in Repository.Query<ProviderRanking>()
                   orderby pr.ProviderRankingFlags.Any(), pr.TimestampUtc
                   select pr;

int count = query.Count();
IEnumerable<ProviderRanking> reviews = query.ToList();

The last two lines produce the errors:

'System.Linq.IQueryable' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?)

And:

'System.Linq.IQueryable' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?)

I was thinking that would work.

Upvotes: 0

Views: 719

Answers (1)

SLaks
SLaks

Reputation: 887433

All LINQ methods (except Cast and OfType) extend generic collection interfaces.

You need to declare your variable as the generic IQueryable<T> interface.
(or just use var to infer that automatically.)

Upvotes: 3

Related Questions