This question is a continuous question of "LINQ casting with a Data.DataTableCollection", here is the link [question]LINQ casting with a Data.DataTableCollection @Lasse Espeholt
I case the same situation. I want to do LINQ query on collection DataTableCollection. But if I write down the following code:
from dataTable in dataSet.Tables
The visual studio will report a error "Could not find an implementation of the query pattern for source type 'System.Data.DataTableCollection'". So the solution is change the code to following:
from dataTable in dataSet.Tables.Cast<DataTable> ()
So I dig the the root cause from internet. And I found some clue as "A typical LINQ to Objects query expression not only takes a class that implements IEnumerable as its data source, but it also returns an instance of this same type." in this page. So I wonder DataTableCollection don't inherit the interface IEnumerable. But according I checking in MSDN, I found the inheritence relationship of DataTableCollection is as following:
DataTableCollection
InternalDataCollectionBase
ICollection
IEnumerable
So this inheritence relationship means that DataTableCollection only inherit the interface IEnumerable, don't inherit the interface IEnumerable. So it can't support the LINQ query. And the solution is using the cast method the transform to IEnumerable and then can do LINQ query.
So my summary as the class which want to enable the functionality of LINQ to object, it has to inherit the both interface IEnumerable and IEnumerable.
Is my summary right? And what's the difference between IEnumerable and IEnumerable?