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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. LINQ
  4. Is there a way to do a 'select all' inside a select that returns an anon' object?

Is there a way to do a 'select all' inside a select that returns an anon' object?

Scheduled Pinned Locked Moved LINQ
databasequestion
2 Posts 2 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.
  • R Offline
    R Offline
    Red_Wizard_Shot_The_Food
    wrote on last edited by
    #1

    Lets say "Things" is a table with 100+ columns and I want to pull back an anonymous object that is a combination of an entire "Thing" plus 3 or 4 related entries from Thing.Stuff.Blah e.g

    database.Thing.Select(thing=> new {Name = thing.Stuff.Blah.Name, Age = thing.Stuff.Blah.Age, Car = thing.Stuff.Blah.Car, thing});

    To produce an object like so: Name, Age, Car, ... plus another 100 properties from the Things table Or do i have to type out all those columns names eg: thing.x, thing .y and so on?? Thanks :)

    H 1 Reply Last reply
    0
    • R Red_Wizard_Shot_The_Food

      Lets say "Things" is a table with 100+ columns and I want to pull back an anonymous object that is a combination of an entire "Thing" plus 3 or 4 related entries from Thing.Stuff.Blah e.g

      database.Thing.Select(thing=> new {Name = thing.Stuff.Blah.Name, Age = thing.Stuff.Blah.Age, Car = thing.Stuff.Blah.Car, thing});

      To produce an object like so: Name, Age, Car, ... plus another 100 properties from the Things table Or do i have to type out all those columns names eg: thing.x, thing .y and so on?? Thanks :)

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

      Not clear on why this is required, I'd probably just return the "thing" myself to access the properties that way. You could try writing a dynamic expression to do the select: google "LINQ dynamic expressions" for more info. You'd have to write a function that uses reflection to iterate through the properties and any sub-properties to populate the select.

      '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