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. Choose table dynamically in EF

Choose table dynamically in EF

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.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    For my client's sake, I have forgone pride and dignity and opted for the exampled means of choosing an entityset to select from, but I need to join this to another, fixed, entityset, and this challenge is beyond me today. I need to project a set of attributes from both Department*n,* and another entity set called Sites. I can join Department1 and Sites, but I am stumped at joining oq to Sites to select a projection of fields from both. Must I prostitute myself further, and repeat the entire query in each case of the switch statement?

                case "Department1":
                    var b = from d1 in ents.Department1
                            join w in ents.Sites on d1.Sites.SiteId equals w.SiteId
                            select d1;
                    selectedDepartments.DataSource = b;
                    break;
                case "Department2":
                    var c = from d1 in ents.Department2
                             join w in ents.Sites on d1.Sites.SiteId equals w.SiteId
                             select d1;
                    break;
                case "Department3":
    
    R 1 Reply Last reply
    0
    • B Brady Kelly

      For my client's sake, I have forgone pride and dignity and opted for the exampled means of choosing an entityset to select from, but I need to join this to another, fixed, entityset, and this challenge is beyond me today. I need to project a set of attributes from both Department*n,* and another entity set called Sites. I can join Department1 and Sites, but I am stumped at joining oq to Sites to select a projection of fields from both. Must I prostitute myself further, and repeat the entire query in each case of the switch statement?

                  case "Department1":
                      var b = from d1 in ents.Department1
                              join w in ents.Sites on d1.Sites.SiteId equals w.SiteId
                              select d1;
                      selectedDepartments.DataSource = b;
                      break;
                  case "Department2":
                      var c = from d1 in ents.Department2
                               join w in ents.Sites on d1.Sites.SiteId equals w.SiteId
                               select d1;
                      break;
                  case "Department3":
      
      R Offline
      R Offline
      Riaan Booyzen
      wrote on last edited by
      #2

      Hi, If they are associated and mapped in the Entity Container, then you can simple load the reference's for your entity set. i.e. var b = from d1 in ents.Department1 select d1; List _departmentlist = b.tolist(); //now you can loop through this and load the sitereference for each department if you like like foreach(Department yourDept in _departmentlist) { yourDept.sitereference.load(); } Alternatively, have you thought about creating a view? A view is imported into your entity container as an entity set on its own, providing nice flexibility for complex situations.

      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