Type Inference and LINQ

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Masa Ito

    Type Inference and LINQ

    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.TableN ame.ToString.St artsWith("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.Dat aTableCollectio n - but this isn't ienumerable? I can
    add .AsQueryable but then the RawTable.TableN ame gets a 'Late Binding'
    error.

    Sorry for a possibly stupid question!

  • Cor Ligthert[MVP]

    #2
    Re: Type Inference and LINQ

    Maso,

    Have you option strict On?

    Dim qRawTables = From RawTable In ds.Tables _
    Where DirectCast(RawT able,
    DataTable).Tabl eName.StartsWit h("RAW")

    Cor

    Comment

    • Masa Ito

      #3
      Re: Type Inference and LINQ

      On 2008-02-11 21:21:19 -0500, "Cor Ligthert[MVP]" said:
      Have you option strict On?
      >
      Dim qRawTables = From RawTable In ds.Tables _
      Where DirectCast(RawT able,
      DataTable).Tabl eName.StartsWit h("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.TableN ame.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?

      Comment

      • Cor Ligthert[MVP]

        #4
        Re: Type Inference and LINQ

        Masa,

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

        Cor

        Comment

        Working...