Type Inference and LINQ

  • Thread starter Thread starter Masa Ito
  • Start date Start date
M

Masa Ito

I am really jazzed about LINQ - but am struggling with some basics -
like when does it infer the datatype?

Simple example - I want to get all the tables in a typed dataset that
have "RAW" in the name. I would have thought that:

Dim qRawTables = From RawTable In ds.Tables _
Where RawTable.TableName.ToString.StartsWith("RAW")

When I hover over qRawTables it is an object. So it is not using type
inferrence right? ds.tables is returning a
System.Data.DataTableCollection - but this isn't ienumerable? I can
add .AsQueryable but then the RawTable.TableName gets a 'Late Binding'
error.

Sorry for a possibly stupid question!
 
Maso,

Have you option strict On?

Dim qRawTables = From RawTable In ds.Tables _
Where DirectCast(RawTable,
DataTable).TableName.StartsWith("RAW")

Cor
 
Have you option strict On?

Dim qRawTables = From RawTable In ds.Tables _
Where DirectCast(RawTable,
DataTable).TableName.StartsWith("RAW")

Cor,

Thanks (as always!)

I didn't think to try a DirectCast - it works great. I also tried
doing from RawTable as Datable and it worked... like this:

Dim qRawTables = From Rawtable as Datatable in ds.Tables _
Where Rawtable.TableName.StartsWith("RAW")

Do you know why it doesn't already know that RawTable is a datatable?
Other queries that I do are able to infer the type - is it because
ds.Tables could return other things than datatables?
 
Back
Top