简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM