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. Include() Question

Include() Question

Scheduled Pinned Locked Moved LINQ
questiondatabasehelptutorial
2 Posts 2 Posters 5 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.
  • E Offline
    E Offline
    eddieangel
    wrote on last edited by
    #1

    I want to include data from a foreign key table to one of my foreign key tables. How do I accomplish this? Example: This query returns all of my observations, Observation has a foreign key relationship to Property.

    return this.ObjectContext.Observations.Include("Defect").Include("Property").Include("Location");

    This query returns all properties, separate of Observation:

    return this.ObjectContext.Properties.Include("StreetSuffix");

    The issue is that I want to include "StreetSuffix" in the first query so that I can access the street suffix name from the datagrid that is populated by the top query. The streetsuffix is related to observation through property. Cheers, --EA

    V 1 Reply Last reply
    0
    • E eddieangel

      I want to include data from a foreign key table to one of my foreign key tables. How do I accomplish this? Example: This query returns all of my observations, Observation has a foreign key relationship to Property.

      return this.ObjectContext.Observations.Include("Defect").Include("Property").Include("Location");

      This query returns all properties, separate of Observation:

      return this.ObjectContext.Properties.Include("StreetSuffix");

      The issue is that I want to include "StreetSuffix" in the first query so that I can access the street suffix name from the datagrid that is populated by the top query. The streetsuffix is related to observation through property. Cheers, --EA

      V Offline
      V Offline
      Vincent Blais
      wrote on last edited by
      #2

      Just add StreetSuffix in the Property include

      return this.ObjectContext.Observations.Include("Property.StreetSuffix")

      Also check this blog post for a Include using lamba expression: Improving Objectquery-lt-t-gt-include[^] Be careful with Include as the resulting query can become quite complex. Sometime it can be more efficient to do multiple simple query.

      Vince Remember the dead, fight for the living

      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