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. How to execute LINQ query when I have the table`s name stored in a variable

How to execute LINQ query when I have the table`s name stored in a variable

Scheduled Pinned Locked Moved LINQ
databasecsharplinqtutorial
4 Posts 4 Posters 4 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.
  • M Offline
    M Offline
    moh123456
    wrote on last edited by
    #1

    want to do execute a LINQ query, and I have the name of the table to query stored in a variable: string tableName = "SomeTable""; DataContext db = new DataContext(); var vResult = from t in db.tableName where t.Id = ....

    L M 2 Replies Last reply
    0
    • M moh123456

      want to do execute a LINQ query, and I have the name of the table to query stored in a variable: string tableName = "SomeTable""; DataContext db = new DataContext(); var vResult = from t in db.tableName where t.Id = ....

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can use Reflection for such scenario. Find following link useful for the same. http://stackoverflow.com/questions/3374133/how-to-execute-linq-query-when-i-have-the-tables-name-stored-in-a-variable Hope this help!

      Peace ON In Simple Sense... Start Shining Stories We Live...

      N 1 Reply Last reply
      0
      • L Lost User

        You can use Reflection for such scenario. Find following link useful for the same. http://stackoverflow.com/questions/3374133/how-to-execute-linq-query-when-i-have-the-tables-name-stored-in-a-variable Hope this help!

        Peace ON In Simple Sense... Start Shining Stories We Live...

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        You do realize you have pointed to the same question, the code given my the OP is the same, and gave the same useless answer, Use reflection, with no elaboration.


        Failure is not an option; it's the default selection.

        1 Reply Last reply
        0
        • M moh123456

          want to do execute a LINQ query, and I have the name of the table to query stored in a variable: string tableName = "SomeTable""; DataContext db = new DataContext(); var vResult = from t in db.tableName where t.Id = ....

          M Offline
          M Offline
          MWRivera
          wrote on last edited by
          #4

          This link may come in handy to gather the primary key fields: http://naspinski.net/post/Get-the-Primary-Key-PropertyInfo-of-any-Linq-to-SQL-Table.aspx[^] Let us know if you make any progress.

          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