Connecting Tech Pros Worldwide Forums | Help | Site Map

Type Inference and LINQ

Masa Ito
Guest
 
Posts: n/a
#1: Feb 11 '08
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!


Cor Ligthert[MVP]
Guest
 
Posts: n/a
#2: Feb 12 '08

re: Type Inference and LINQ


Maso,

Have you option strict On?

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

Cor

Masa Ito
Guest
 
Posts: n/a
#3: Feb 12 '08

re: Type Inference and LINQ


On 2008-02-11 21:21:19 -0500, "Cor Ligthert[MVP]" said:
Quote:
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?

Cor Ligthert[MVP]
Guest
 
Posts: n/a
#4: Feb 12 '08

re: Type Inference and LINQ


Masa,

How can it know that it is a datatable and not a relation.

Cor
Closed Thread