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. Dynamic columns from 2 joined tables

Dynamic columns from 2 joined tables

Scheduled Pinned Locked Moved LINQ
databasecsharplinqhelptutorial
2 Posts 1 Posters 1 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
    Mycroft Holmes
    wrote on last edited by
    #1

    I have 2 pivot tables to be joined from SQL. I have the 2 tables and I have joined then with the following linq, and I even got the result I expect (eventually).

    var query = from Lmt in dtLimit.AsEnumerable()
    join Ut in dtUtil.AsEnumerable()
    on Lmt.Field("LimitID") equals
    Ut.Field("LimitID")
    select new
    {
    LimitID = Lmt.Field("LimitID"),
    LimitName = Lmt.Field("LimitName"),
    Element = Lmt.Field("Element"),
    Limit = Lmt.Field("Limit"),
    Amount = Ut.Field("Amount"),
    Util = Ut.Field("Util")
    };

    The problem is I have 1 or more columns for both dtLimit and dtUtil that are created using a pivot and are therefore dynamic. I can identify the names and data types of the columns at runtime but have no idea how to add them to the above query. I would even settle for ALL columns from the 2 datatables as I would then hide the DGV columns I did not want.

    Never underestimate the power of human stupidity RAH

    M 1 Reply Last reply
    0
    • M Mycroft Holmes

      I have 2 pivot tables to be joined from SQL. I have the 2 tables and I have joined then with the following linq, and I even got the result I expect (eventually).

      var query = from Lmt in dtLimit.AsEnumerable()
      join Ut in dtUtil.AsEnumerable()
      on Lmt.Field("LimitID") equals
      Ut.Field("LimitID")
      select new
      {
      LimitID = Lmt.Field("LimitID"),
      LimitName = Lmt.Field("LimitName"),
      Element = Lmt.Field("Element"),
      Limit = Lmt.Field("Limit"),
      Amount = Ut.Field("Amount"),
      Util = Ut.Field("Util")
      };

      The problem is I have 1 or more columns for both dtLimit and dtUtil that are created using a pivot and are therefore dynamic. I can identify the names and data types of the columns at runtime but have no idea how to add them to the above query. I would even settle for ALL columns from the 2 datatables as I would then hide the DGV columns I did not want.

      Never underestimate the power of human stupidity RAH

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Well I fixed this problem, chucked Linq and went back to TSQL, took me a couple of hours to craft the procedure but I got the job done. I took one look at Dynamic Linq, which seems to assume a strongly type dataset every time and shuddered in horror. I despise dynamic TSQL and I think Linq to Dataset leaves a LOT to be desired, I can't imagine trying to debug dynamic Linq. I feel we are creating a support nightmare with linq and Lambda.

      Never underestimate the power of human stupidity RAH

      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