16,004,602 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by John Wigger (Top 1 by date)
John Wigger
23-Aug-11 10:08am
View
Deleted
Riz,
The key is using multiple steps. You can think of the WMI Linq provider as being similar to a Linq provider for SQL Server. These providers implement the IQueryable interface. They actually take your code as data in the form of what are called Expression Trees. It can be challenging to write this kind of provider code. So in the case of Linq To WMI it is better to give it is a simpler query that it can handle properly. Unfortunately Linq to WMI can't do all of the things that Linq to Objects does. In other words, you can write Linq to WMI code that compiles but barfs at runtime. Using two steps allows the simpler query to run properly under Linq to WMI and the more advanced query processing to be done under Linq to Objects. Linq to Objects guarantees that it will correctly handle anything that can be compiled. My second example shows a query that would fail at runtime using a single-step Linq to WMI query.
Finally, the AsEnumerable method is a way to bypass the particular Linq provider for a certain query and use Linq to Objects instead.
Good question! Grasping the way Linq providers work is pretty tough stuff. Fortunately, we normally don't need to think too much about them.