Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3391740
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:50:16+00:00 2026-05-18T03:50:16+00:00

Ok, I must be working too hard because I can’t get my head around

  • 0

Ok, I must be working too hard because I can’t get my head around what it takes to use the Entity Framework correctly.

Here is what I am trying to do:

I have two tables: HeaderTable and DetailTable. The DetailTable will have 1 to Many records for each row in HeaderTable. In my EDM I set up a Relationship between these two tables to reflect this.

Since there is now a relationship setup between these tables, I thought that by quering all the records in HeaderTable, I would be able to access the DetailTable collection created by the EDM (I can see the property when quering, but it’s null).

Here is my query (this is a Silverlight app, so I am using the DomainContext on the client):

 // myContext is instatiated with class scope
  EntityQuery<Project> query = _myContext.GetHeadersQuery();


  _myContext.Load<Project>(query);   

Since these calls are asynchronous, I check the values after the callback has completed. When checking the value of _myContext.HeaderTable I have all the rows expected. However, the DetailsTable property within _myContext.HeaderTable is empty.

foreach (var h in _myContext.HeaderTable)  // Has records
    {
      foreach (var d in h.DetailTable)  // No records
      {
        string test = d.Description;
      }

I’m assuming my query to return all HeaderTable objects needs to be modified to somehow return all the HeaderDetail collectoins for each HeaderTable row. I just don’t understand how this non-logical modeling stuff works yet.

What am I doing wrong? Any help is greatly appriciated. If you need more information, just let me know. I will be happy to provide anything you need.

Thanks,

-Scott

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:50:17+00:00Added an answer on May 18, 2026 at 3:50 am

    What you’re probably missing is the Include(), which I think is out of scope of the code you provided.

    Check out this cool video; it explained everything about EDM and Linq-to-Entities to me:
    http://msdn.microsoft.com/en-us/data/ff628210.aspx

    In case you can’t view video now, check out this piece of code I have based on those videos (sorry it’s not in Silverlight, but it’s the same basic idea, I hope).

    The retrieval:

    public List<Story> GetAllStories()
    {
        return context.Stories.Include("User").Include("StoryComments").Where(s => s.HostID == CurrentHost.ID).ToList();
    }
    

    Loading the the data:

    private void LoadAllStories()
    {
        lvwStories.DataSource = TEContext.GetAllStories();
        lvwStories.DataBind();
    }
    

    Using the data:

    protected void lvwStories_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            Story story = e.Item.DataItem as Story;
    
            //  blah blah blah....
    
            hlStory.Text = story.Title;
            hlStory.NavigateUrl = "StoryView.aspx?id=" + story.ID;
            lblStoryCommentCount.Text = "(" + story.StoryComments.Count.ToString() + " comment" + (story.StoryComments.Count > 1 ? "s" : "") + ")";
            lblStoryBody.Text = story.Body;
            lblStoryUser.Text = story.User.Username;
            lblStoryDTS.Text = story.AddedDTS.ToShortTimeString();
        }            
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on updating one of our applications. It must use .NET 2.0. One
I'm working on a project that'll use PEAR packages. Because you never know what
I am creating an application which must execute a function that takes too long
When working with a collection of forms that the user must step through, is
Im working on a dialog box in which several rules must be satisfied before
I am working on a project that must store very large datasets and associated
I am working on an ASP.Net web application that must print dynamically created labels
Working on a project where a sequential set of methods must be run every
I am working on a project with a library and I must work with
I'm working on a project where, i must provide the user a textbox where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.