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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:01:14+00:00 2026-06-07T20:01:14+00:00

I am having two object classes public class User { public Guid Id {

  • 0

I am having two object classes

public class User
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    // Navigation
    public ICollection<Product> Products { get; set; }
}

public class Product
{
    public Guid Id { get; set; }

    // Navigation
    public User User { get; set; }
    public Guid User_Id { get; set; }

    public string Name { get; set; }
}

When i load a user using dataContext, i get the list of Products being null (this is ok).

If i add “virtual” keyword to Products list,

public virtual ICollection<Product> Products { get; set; }

when i load the user, i get the Products list as well.

Why is this happening? I thought that “virtual” keyword is used for not loading the entities unless you explicit this (using an “Include” statement)

I think i got it all 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-06-07T20:01:15+00:00Added an answer on June 7, 2026 at 8:01 pm

    This is wrong

    “virtual” keyword is used for not loading the entities unless you
    explicit this (using an “Include” statement)

    Lazy Loading means that entities will be automatically loaded when you first access collection or navigation property, and that will happen transparently, as though they were always loaded with parent object.

    Using “include” is loading on demand, when you specify properties you want to query.

    Existence of virtual keyword is related only to lazy loading. virtual keyword allows entity framework runtime create dynamic proxies for your entity classes and their properties, and by that support lazy loading. Without virtual, lazy loading will not be supported, and you get null on collection properties.

    Fact is that you can use “include” in any case, but without lazy loading it is the only way to access collection and navigation properties.

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

Sidebar

Related Questions

I'm having two Java classes. The first implements the following method: @Override public void
I have two classes like this (simplified and renamed): class Base { public: virtual
Summary: I want to save two classes of the same name and different namespaces
I am having trouble getting two classes to interact. Here is the code for
I have two classes Event and Review. The event has an instance object Review
Alongside the implicit User Interface thread, i have made two threads (runnables), both having
I'm having some trouble in python with classes and objects. I have two classes,
I'm having two DateTime -objects: $start = new DateTime('first thursday of June 2012'); $end
I'm having trouble with refreshing objects in my database. I have an two PC's
I have two list of different objects : List<Report> List<Newsletter> each having a 'created

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.