Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. return type problem

return type problem

Scheduled Pinned Locked Moved LINQ
databasehelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nilish
    wrote on last edited by
    #1

    I am extracting two fields from two tables , first field is from first table and other is from second table.When i return the query , i am unable to get the fields name like i have a function

    private function ret()as object
    dim query = from p in datacontext.gettable(of tablename) _
    group join a in datacontext.gettable(of tablename1) _
    on p.id equals a.id into c = group from c1 in c.DefaultIfEmpty() _
    selcet field1 = p.name , field2 = c1.name1
    return query
    end sub

    private sub abc()
    dim query = ret()
    'When i write the query.
    'I does not display the field1 and field2.
    'Why it is happening
    end sub

    P 1 Reply Last reply
    0
    • N Nilish

      I am extracting two fields from two tables , first field is from first table and other is from second table.When i return the query , i am unable to get the fields name like i have a function

      private function ret()as object
      dim query = from p in datacontext.gettable(of tablename) _
      group join a in datacontext.gettable(of tablename1) _
      on p.id equals a.id into c = group from c1 in c.DefaultIfEmpty() _
      selcet field1 = p.name , field2 = c1.name1
      return query
      end sub

      private sub abc()
      dim query = ret()
      'When i write the query.
      'I does not display the field1 and field2.
      'Why it is happening
      end sub

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You're returning an object. The only methods available on an object are ToString(), Equals(), GetType() and GetHashCode(). Try returning a more appropriate type from your function.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      N 1 Reply Last reply
      0
      • P Pete OHanlon

        You're returning an object. The only methods available on an object are ToString(), Equals(), GetType() and GetHashCode(). Try returning a more appropriate type from your function.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        N Offline
        N Offline
        Nilish
        wrote on last edited by
        #3

        If i am fetching the data from two tables , say , field1 from table1 and field2 from table2 .In this case what should I return ?

        H 1 Reply Last reply
        0
        • N Nilish

          If i am fetching the data from two tables , say , field1 from table1 and field2 from table2 .In this case what should I return ?

          H Offline
          H Offline
          Howard Richards
          wrote on last edited by
          #4

          LINQ querues return IEnumerable(of T) In your example you're creating an anonymous type[^], so T is an anonymous type, so passing it as a return of a function is going to be an issue. Object will work of course, but how do you get the results? 1) don't use an anonymous type, use a Structure or Class e.g. Select New MyType With { .field1 = p.name , .field2 = c1.name1 } 2) return an anonymous type and use reflection to get the property values This is what I do for my Report generator - it does not know the type the report will generate, but it gets a list of properties from the report and uses Reflection.

          'Howard

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups