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. Get through all tables of a database

Get through all tables of a database

Scheduled Pinned Locked Moved LINQ
questiondatabase
6 Posts 3 Posters 18 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.
  • U Offline
    U Offline
    User 11883281
    wrote on last edited by
    #1

    I want to get through all tables of a database with a select how can I do it?

    P 1 Reply Last reply
    0
    • U User 11883281

      I want to get through all tables of a database with a select how can I do it?

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

      If you're using LINQ, it depends which database you're targetting. If you were using the old ODBC ways of accessing databases, there was a set of metadata queries that you could perform that were nice and generic - however, as you are using L2S, the method depends on the database provider. For instance, in SQL Server, you could use

      SELECT [FieldList goes here] FROM information_schema.Tables

      U 1 Reply Last reply
      0
      • P Pete OHanlon

        If you're using LINQ, it depends which database you're targetting. If you were using the old ODBC ways of accessing databases, there was a set of metadata queries that you could perform that were nice and generic - however, as you are using L2S, the method depends on the database provider. For instance, in SQL Server, you could use

        SELECT [FieldList goes here] FROM information_schema.Tables

        U Offline
        U Offline
        User 11883281
        wrote on last edited by
        #3

        I'm using Linq (Entity Framework)... what can I do?

        P 1 Reply Last reply
        0
        • U User 11883281

          I'm using Linq (Entity Framework)... what can I do?

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

          Write a stored procedure that gets the values and hook up to that.

          U 1 Reply Last reply
          0
          • P Pete OHanlon

            Write a stored procedure that gets the values and hook up to that.

            U Offline
            U Offline
            User 11883281
            wrote on last edited by
            #5

            I don't have the rights to write a stored procedure... don't ask why ... i'm freaking out with this database...

            Richard DeemingR 1 Reply Last reply
            0
            • U User 11883281

              I don't have the rights to write a stored procedure... don't ask why ... i'm freaking out with this database...

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              You can use the SqlQuery method[^] on the Database[^] to execute a raw query:

              IEnumerable<string> tables = context.Database.SqlQuery<string>("SELECT QUOTENAME(s.name) + '.' + QUOTENAME(t.name) As TableName FROM sys.tables As t INNER JOIN sys.schemas As s ON s.schema_id = t.schema_id ORDER BY s.name, t.name");

              Entity Framework Raw SQL Queries[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              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