Where is System.Linq in .NET 4.0?
I migrated an asp.net app to 4.0. Now I am getting an error "The type or namespace name 'IQueryable' could not be found". The reference to System.Linq is invalid and I can't find it in the reference list. Where did System.Linq go?
@splat1985
I’ve looked into this a bit, and I’m able to reproduce what you’re describing, or at least something close to it, using EFCore 3.1.8.
The DbSet class implements more than one interface, both IQueryable and IAsyncEnumerable. So when accessing a property of type DbSet directly, it will look for extension methods that extend both of those interfaces to find a matching extension method. In a pure EF Core installation, there are no extensions available for IAsyncEnumerable. However, the System.Linq.Async library, published by the Rx.NET team, adds LINQ extensions to IAsyncEnumerable. This library is included as a dependency of the Couchbase SDK so we can use some of it’s features and offer them to the SDK’s users, though you could get this dependency from many other places.
Featured content:What makes a good business card? 10 golden rules
Custom Postcard Printing - Multiple Sizes and Premium Options
5 Things to Know Before Buying New Children's Books Printing
Printing Costs: How To Accurately Calculate Your Printing Cost Per Page
The Importance of Book Selection
8 Essential Principles of Good Business Card Design
Material Design Principles For Your Business Card
Once the System.Linq.Async package is included in your project, both interfaces now have an implementation for Where, and C# can’t tell which is the best to choose. In fact, for your use case the IQueryable extension is the right choice, but the C# compiler can’t know that.
The workaround is to use .AsQueryable()
which will typecast the DbSet to IQueryable and remove the ambiguity from the C# compiler. In fact, this is documented on that method in EF Core:
This is a convenience method to help with disambiguation of extension methods in the same namespace that extend both interfaces.
Hopefully this helps!
Where is System.Linq in .NET 4.0?
System.Linq is Ambiguous - .NET SDK
Featured content:Book Printing Basics And What You Need To Know
Books for Teaching Students to Compare and Contrast
What details should be on a business card?
What are the 4 types of 3D printing?
Children’s Book Sales Statistics – WordsRated
Your 3 ¼-year-old: Milestones and development
Choosing Food Packaging
247
0
0
All Comments (0)
Previous: The Benefits of Using new cosmetic bottles
Next: Where is system LINQ?
Related Articles
If you are interested in sending in a Guest Blogger Submission,welcome to write for us!
Comments