Álvaro García Álvaro García -3 years ago 79
C# Question

IEnumerable can't convert to IQueryable

Until now, I have a .net 4.7 library in which I use IQuery in this mode:

IQueryable<MyType> myIQueryable = mySource;

if(paramIsNew != null)
{
myIQueryable = myIQueryable.where(x => x.IsNew == paramIsNew);
}


And so on for more parameters and conditions.

However, now I am trying to convert this library to a .net standard library, but I am getting the error that I canĀ“t convert an IEnumerable to IQueryable, it exists and explicit conversion.

I don't see the problem really and how to solve it.

Answer Source

That's because Queryable class and so queryable-specific extension methods (like Where), are not part of default .NET Standard libraries. So you use Enumerable.Where extension method, which returns IEnumerable. Your myIQueryable is of type IQueryable hence you are getting compiler error. You need to install System.Linq.Queryable nuget package, then your code with compile.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download