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. C#
  4. C# linq with 3 tables

C# linq with 3 tables

Scheduled Pinned Locked Moved C#
csharpquestiondatabaselinqtutorial
3 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.
  • S Offline
    S Offline
    sc steinhayse
    wrote on last edited by
    #1

    In a C# 2008 application, I have the following linq to sql statement setup so far.

    eDataContext eData = new eDataContext();
    var eSelect = (from iw in eData.Ibooks
    join ip in etData.IPack on iw.P_ID equals ip.P_ID
    join eTrack in eData.eRPT_Trans
    on ip.TNum equals eTrack.P_ID
    where ip.TNum == packageId
    select iw).FirstOrDefault();

    I want to obtain values from the 3 different tables listed in the statement above How do I change the linq statement above so that I can obtain data from all three tables? Thus can you show me how to obtain data from all 3 tables?

    A G 2 Replies Last reply
    0
    • S sc steinhayse

      In a C# 2008 application, I have the following linq to sql statement setup so far.

      eDataContext eData = new eDataContext();
      var eSelect = (from iw in eData.Ibooks
      join ip in etData.IPack on iw.P_ID equals ip.P_ID
      join eTrack in eData.eRPT_Trans
      on ip.TNum equals eTrack.P_ID
      where ip.TNum == packageId
      select iw).FirstOrDefault();

      I want to obtain values from the 3 different tables listed in the statement above How do I change the linq statement above so that I can obtain data from all three tables? Thus can you show me how to obtain data from all 3 tables?

      A Offline
      A Offline
      Aasif Chanandin
      wrote on last edited by
      #2

      As part of your select statement, you can put any fields from the three tables in there, just as if you were doing a select in SQL. Ex: Select {iw, ip, eTrack}. The best thing would be to use select fields instead of all of the fields from all three tables.

      1 Reply Last reply
      0
      • S sc steinhayse

        In a C# 2008 application, I have the following linq to sql statement setup so far.

        eDataContext eData = new eDataContext();
        var eSelect = (from iw in eData.Ibooks
        join ip in etData.IPack on iw.P_ID equals ip.P_ID
        join eTrack in eData.eRPT_Trans
        on ip.TNum equals eTrack.P_ID
        where ip.TNum == packageId
        select iw).FirstOrDefault();

        I want to obtain values from the 3 different tables listed in the statement above How do I change the linq statement above so that I can obtain data from all three tables? Thus can you show me how to obtain data from all 3 tables?

        G Offline
        G Offline
        gazmendmehmeti
        wrote on last edited by
        #3

        eDataContext eData = new eDataContext(); var eSelect = (from iw in eData.Ibooks join ip in etData.IPack on iw.P_ID equals ip.P_ID join eTrack in eData.eRPT_Trans on ip.TNum equals eTrack.P_ID where ip.TNum == packageId select new { iw.P_ID, ip.P_ID, eTrack.P_ID /* Other fields */ } ).FirstOrDefault();

        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