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

  • SEARCH
  • Home
  • 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 8951719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:43:45+00:00 2026-06-15T13:43:45+00:00

Despite I’m completely new to .NET stack, I somehow managed to develop a small

  • 0

Despite I’m completely new to .NET stack, I somehow managed to develop a small N-Tier application involving the following technologies:

WPF -> WCF -> Entity Framework -> SQL Server

My doubt is mainly about how Entity Framework manages the assignment of navigation properties. I’ll put my data contract code to get the ball rollin’ …

[DataContract]
public class Problem
{
    [DataMember]
    public int ProblemId { get; set; }

    [DataMember]
    public String Title { get; set; }

    [DataMember]
    public String Description { get; set; }

    [DataMember]
    public int WorkerId { get; set; }

    [DataMember]
    public int WorkId { get; set; }

    [DataMember]
    [ForeignKey("WorkerId")]        
    public virtual Worker Worker { get; set; }

    [DataMember]
    [ForeignKey("WorkId")]        
    public virtual Work Work { get; set; }
}


[DataContract]
public class Worker
{
    [DataMember]
    public int WorkerId { get; set; }

    [DataMember]
    public String Name { get; set; }    

    [DataMember] 
    public virtual ICollection<Problem> Problems { get; set; }        
}


[DataContract]
public class Work
{
    [DataMember]
    public int WorkId { get; set; }

    [DataMember]
    public String Name { get; set; }      

    [DataMember] 
    public virtual ICollection<Problem> Problems { get; set; }
}

In my Seed method, I’m doing the following:

Work Work1 = new Work()
                                {
                                    WorkId = 1,
                                    Name = "Work1"
                                };

        Worker emp1 = new Worker()
                                {
                                    WorkerId = 1,
                                    Name = "Worker1"
                                };

        Problem Problem1 = new Problem()
                            {
                                ...
                                WorkId = 1,
                                WorkerId = 1
                            };

        Problem Problem2 = new Problem()
                              {
                                  ...
                                  Work = Work1,
                                  Worker = emp1
                              };

        //add objects to the context
        context.Works.Add(Work1);
        context.Workers.Add(emp1);
        context.Problems.Add(Problem1);
        context.Problems.Add(Problem2);

        //added just for testing
        Problem1.Work = Work1;
        Problem1.Worker = emp1;

        //finally: save changes           
        context.SaveChanges();

And the point is: after disposing the context & doing a query like: context.Problems.ToList() … both problem1 & problem2 have its navigation properties (Worker, Work) assigned to Null. WorkerId and WorkId are stored, but no its related Objects inside the Problem Entity.

Am I missing something?

Thank you very much in advance for your answer!

  • 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-06-15T13:43:45+00:00Added an answer on June 15, 2026 at 1:43 pm

    Yes, you need to do

    context.Problems.Include(p=>p.Work).ToList() 
    

    in order to populate the children when you reload them under a new context.

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

Sidebar

Related Questions

Despite being a Project Euler program, the following code doesn't actually concern it much.
Despite the number of similar questions, I haven't yet managed to find any such
Despite following various posts on using and linking to unmanaged C++ code from a
Despite using many sql databases before, I've never actually tried to develop an app
Despite my background with asp .net C#, I've really tried to get my head
Despite a good deal of searching here I haven't been able to find the
Despite using PHP for years, I've never really learnt how to use expressions to
Despite me working with C# ( Windows Forms ) for years, I'm having a
Despite warnings to drop my present course of action, I currently see no better
Despite working on EE for about 3 weeks now, believe it or not, this

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.