Click here to Skip to main content
15,891,607 members

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.