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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:58:40+00:00 2026-06-15T11:58:40+00:00

with entity framework, how should I load object from an object list ? Example.

  • 0

with entity framework, how should I load object from an object list ? Example.

public class Phone
{
    public int Id { get; set; }
    public string Type { get; set; }
    public Corporation Corp { get; set; }
}

public class Corporation 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Phone> Phones { get; set; }
}

// And now, when I get a Corporation class from entity framework,
//I can't access the Phones. I get an error: The value canot be null.
_db.Corporations.First().Name; // Works
_db.Corporations.First().Phones.First().Type; // Fails

How should I load the List properties ?

  • 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-15T11:58:41+00:00Added an answer on June 15, 2026 at 11:58 am

    mark the related entities as virtual to enable lazy loading by default.

    class Corporation
    {
       public int Id {get;set;}
       public virtual List<Phone> Phones {get;set;}
    }
    class Phone
    {
       public int Id {get;set;}
       public virtual Corporation Corp {get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I should mention I'm trying to get Entity Framework\SQL server to do
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
(using Entity Framework) when i write : IEnumerable<string> q = customers /*EF entity*/ .Select
The Entity Framework has a function with this signature: public EntityTypeConfiguration<TEntityType> HasKey<TKey>(Expression<Func<TEntityType, TKey>> keyExpression);
The Entity Framework context object implements a Dispose() method which Releases the resources used
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
As part of our intended migration from Linq2Sql to Entity Framework, we have created
I am binding WPF with Entity-Framework. The Window.DataContext property is set to a Quote.
In Entity Framework 4, what is the difference between Lazy Loading, and using Load()
I have an object hierarchy that looks something like this: public class Book {

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.