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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:58:46+00:00 2026-06-16T03:58:46+00:00

I have an app with Entity Framework 5 code-first this is sample of my

  • 0

I have an app with Entity Framework 5 code-first this is sample of my classes:

public partial class PlaningCourseAssistant 
{
    public PlaningCourseAssistant() {}
    public int ID { get; set; }
    public int PlaningCourseID { get; set; }
    public int AssistantID { get; set; }

    public virtual PlaningCourse PlaningCourse { get; set; }
    public virtual Teacher Assistant { get; set; }
} 

And

public class Teacher 
{
    public Teacher() 
    {
        ...
        this.PlaningCourseAssistants = new HashSet<PlaningCourseAssistant>();
    }
    public int ID { get; set; }
    public string Name{ get; set; }
    ....
    public virtual ICollection<PlaningCourseAssistant> PlaningCourseAssistants { get; set; }
}

And

public partial class PlaningCourse 
{
    public PlaningCourse() 
    {
    ...
        this.PlaningCourseAssistants = new HashSet<PlaningCourseAssistant>();
    }
    public int ID { get; set; }
    public string Title { get; set; }
    ...
    public virtual ICollection<PlaningCourseAssistant> PlaningCourseAssistants { get; set; }
}

when i add a new object to my PlaningCourseAssistant like this :

var pcb = new PlaningCourseAssistant 
{
    PlaningCourseID = CourseID,
    AssistantID = assistantID,
};
try 
{
    planingCourseAssistantService.Add(pcb);
    uow.SaveChanges();
} catch { }

afterward when i want to get PlaningCourseAssistant list, the added PlaningCourseAssistant‘s Assistant navigation key is null.

Why this happen? And how can I fix this?

  • 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-16T03:58:48+00:00Added an answer on June 16, 2026 at 3:58 am

    EF can not lazy load the ‘Assistant’ property because the PlaningCourseAssistant instance you are using is not a proxy created by EF.

    You can either use explicit loading

    context.Entry(pcb).Reference(p => p.Assistant).Load();
    context.Entry(pcb.Assistant).Collection(p => p.PlaningCourseAssistant).Load();
    

    Or let EF create a proxy instance of PlaningCourseAssistant

    var pcb = context.PlaningCourseAssistants.Create();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Entity Framework CTP with Code-First as in this tutorial by
I have a small MVC 3 app using Entity Framework Code First and use
I am using Entity Framework 4.1 code first in an MVC 3 app. I
Using Code First Entity Framework with .NET MVC 4 I have created a new
I'm currently developing an app using ASP.NET MVC3 and Entity Framework 4.1 Code First
I have following entity framework code first code. The tables are created and data
I have some basic knowledge of Entity Framework 4.1 Code First, but haven't used
I am using entity framework code first and also I have data seeding code
I'm trying to use Entity Framework 5 Code First. I've created model classes and
I have an app using the ADO.NET entity framework (the VS2008 version, not the

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.