Linq TypedDataTable Extension Methods - The REAL List.

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
in the Help, and on MSDN this is what is listed for Select()

Name Description
Select() Gets an array of all DataRow objects. (Inherited from DataTable.)
Select(String) Gets an array of all DataRow objects that match the filter criteria in order of primary key (or lacking one, order of addition.) (Inherited from DataTable.)
Select(String, String) Gets an array of all DataRow objects that match the filter criteria, in the specified sort order. (Inherited from DataTable.)
Select(String, String, DataViewRowState) Gets an array of all DataRow objects that match the filter in the order of the sort that match the specified state. (Inherited from DataTable.)
Top

But if you have ever used a TypedDataTable (and are using DataSetExtensions) you know that there are three other Select() methods

VB.NET:
<Extension> _
Public Shared Function [Select](Of TRow As DataRow, S)(ByVal source As TypedTableBase(Of TRow), ByVal selector As Func(Of TRow, S)) As EnumerableRowCollection(Of S)

<Extension> _
Public Shared Function [Select](Of TRow, S) _
  (ByVal source As EnumerableRowCollection(Of TRow), ByVal selector As Func(Of TRow, S)) As EnumerableRowCollection(Of S)

these two i pulled from refractor(even though they look nothing like that in the intellisense), but the third i had to transpose from intellisense because I can't find it any where:
VB.NET:
MyDataTable.Select(Of TResut) _
  (selector as System.Func(of MyDataTableRow, Integer, TResult)) _
   As Collections.Generic.IEnumerable(Of TResult)


Now, I've used some of the delegate functions in the past, that many of the Linq extension sets require, and they can be very helpful. But where is the documentation for these?

I expect they are a more advanced selection method from the datatable, so as to reduce the complexity of the 'filterExpression' that the other DataTable.Select() methods use, or perhaps for even those special moments where a "filterExpression" is useless for the criteria that determines selection. I really want to use something like this, (a delegate select back method) and I don't want to have to reinvent the wheel. But there is no documentation on these functions.

Example: What is the TResult in the third function? What's it For? Should not the TResult be the MyDataTableRow class? These are questions documentation would help with but I can't find anything anywhere on the dataset extensions for the TypedDataTable (or anything that looks remotely like what I see in intellisense).

Thanks
Jaeden "Sifo Dyas" al'raec Ruiner
 
How to know, or how to find out? A typed data table inherits TypedTableBase(Of T), which inherits DataTable and implements IEnumerable and IEnumerable(Of T). The first four listed is the DataTable Select overloads. Linq has a class called Enumerable that contains extension methods for objects that implement IEnumerable(Of T), here you find two more Select overloads, the (Of TResult) ones. How about the Select(Of S) one? Using help index for "select(of" I came across TypedTableBaseExtensions.Select, which is the seventh and last overload. TypedTableBaseExtensions class contains extension methods for TypedTableBase(Of T) class.

I just happened to come across Enumerable (System.Linq) and TypedTableBaseExtensions (System.Data.DataSetExtensions) classes and don't know if there is is a logic way to find such cases.
 
Linq has a class called Enumerable that contains extension methods for objects that implement IEnumerable(Of T), here you find two more Select overloads, the (Of TResult) ones.
Well, I don't know which help I have, but mine doesn't list Select under IEnumerable(Of T) (i already looked there)
the listed members in the IEnumerable(Of T) go from "Reverse()", "SequenceEqual()", "Single()". So there are no Select() methods listed there. I had to find them in Reflector.
I just happened to come across Enumerable (System.Linq) and TypedTableBaseExtensions (System.Data.DataSetExtensions) classes and don't know if there is is a logic way to find such cases.

I ended up stumbling into that one, but I guess my real frustration is that it doesn't quite explain the "S" type-parameter. I normally understand the typeparams for such generic functions, but it appears that these Select() extensions are transformations for every record (row) in a DataTable, not a expansion of the Select("filter") method. are these just ways to convert an entire TypedDataTable full of strongly typed rows into a enumerated collection of another Data Row type, or for selecting creating a list of one column's values, or what? I was looking for a way to basically to use a more advanced Select("filter") style method, but one that used a call back (delegate) for each entry to determine if it was to b e used or not. The help documentation was not to clear on the existence of such a method/extension method. In the end, I think i'm just going to write my own. *smile*

Thanks
 
Well, I don't know which help I have, but mine doesn't list Select under IEnumerable(Of T) (i already looked there)
JohnH said:
a class called Enumerable that contains extension methods
That means Enumerable class (System.Linq) has the extension methods. These are extensions that operate for IEnumerable(Of T) objects.
doesn't quite explain the "S" type-parameter.
I think it is easy to read in help that S type means the return value EnumerableRowCollection(Of S), that is the result of the Func(Of TRow, S) transformation function. The remarks add this:
help said:
This projection method requires the transformation function, selector, to produce one value for each value in the source sequence, source. If selector returns a value that is itself a collection, the consumer must traverse the sub-sequences manually.
Don't forget all these three Select extensions exists for Linq functionality.
 

Latest posts

Back
Top