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 866423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:48:09+00:00 2026-05-15T09:48:09+00:00

I need to be to create an entity data model in the EF version

  • 0

I need to be to create an entity data model in the EF version 1, because my web host doesn’t have Framework 4.0 yet. Below is just a simple example to show the problem.

I have 3 tables, one Users table, another Webpages table, and one table with Visits. The former two tables each have a one-to-many relationship with the Visits table (which basically works as a many-to-many relationship, only the Visits table has its own primary key and extra fields)

With the 4.0 version this works, but it doesn’t with v.1. “Visits” has a count of 0, so the test string returns “”… Why, and how would I be able to access the foreign key relation in v.1?

UsersEntities context = new UsersEntities();
var users = context.Users;
string result = "";
foreach (var user in users)
{
    foreach (var visit in user.Visits)
    {
        result += visit.Webpage.Url + "\n";
    }
}

So the foreach loop loops through the users, which it gets ok, but the inner loop is never entered because there are no Visits returned. Again, in Framework 4.0 it works fine, using the same database.

So what’s wrong?

  • 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-15T09:48:10+00:00Added an answer on May 15, 2026 at 9:48 am

    Simply change your code to this:

    UsersEntities context = new UsersEntities(); 
    var users = context.Users.Include("Visits"); 
    string result = ""; 
    foreach (var user in users) 
    { 
        foreach (var visit in user.Visits) 
        { 
            result += visit.Webpage.Url + "\n"; 
        } 
    } 
    

    Notice the Include(…) that tells EF to eagerly load each User’s visits.

    With that in place it should work.

    Actually if Webpage is a navigation too, you might need:

    Include("Visits.Webpage");
    

    Hope this works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple entity data model where I have two entities and a
I have a rather simple data model, but I have a centric entity called
I have created an entity data model from my database. however in certain areas
I have created a custom entity because I need to populate an entity with
Is it possible to create Entity Data Model (edmx file) from MS Access Database
I have a one to many relationship in my core data model. I need
I need to create and combine several expressions for child entity into one to
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I need to create a WP site which will have multiple subjects. Each subject
Imaging the following 3 relationships in a data model Entity > Path > Link

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.