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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:28:34+00:00 2026-06-10T18:28:34+00:00

I am building a website with a rather complex SQL database. I made a

  • 0

I am building a website with a rather complex SQL database.
I made a Query class, which holds multiple primitive fields (which all work fine) and also multiple List<SomeType>. SomeType is also defined under the Models folder in my solution. It also holds single instances of SomeType. Then, I made a QueryDBContext class which inherits DbContext.

I have a Generate function which receives a string and creates a fully formed Query instance. If I immediately send it to my View – it works fine. But if I store it in my DB – only the primitive values are kept, and the reference types (both Lists<SomeType> and SomeType) are null.

I believe the problem is that EF doesn’t support reference types – or maybe I need something special for this case?
Here’s Query

public class Query
{
    [Key]
    public int id { get; set; }

    public SomeType Base { get; set; }
    public List<SomeType> Derived { get; set; }
    //more of these

    public string SmallGraphImage { get; set; }
    public string MediumGraphImage { get; set; }
    public string LargeGraphImage { get; set; }
}
public class QueriesDBContext : DbContext
{
    public DbSet<Query> Queries { get; set; }
}

Here’s SomeType

public class SomeType
{
    [Key]
    public int id { get; set; }
    public string ExpandedOutForm { get; set; }
    public string ExpandedInForm { get; set; }
    //more strings
}

Note: The database works fine for primitives. For developing purposes, I made a Controller which deletes & rebuilds the database for each modification. I also tried replacing List with IList.

If EF doesn’t support reference types, what should I do? Will it work on structs ? How can I store Lists inside a database entry? (Yeah, I could store it in another table with its ID – but I believe EF has a more elegant solution for 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-10T18:28:36+00:00Added an answer on June 10, 2026 at 6:28 pm

    I believe the problem is that EF doesn’t support reference types

    The Entity Framework does support reference types. With the default configuration those will be mapped to a seperate database table. In your case, a Query_id column will be added to the table ‘SomeTypes’. The Entity Framework will use those to create SQL Joins when loading data.

    The reason why your properties are showing as NULL has nothing to do with this. It has to do with how the Entity Framework loads data. By default, EF will not load a whole object graph from the start. This would mean that if your SomeType references another class which references another… and you would load the whole database in one call.

    You have two options:

    • Explicitly loading the references. You tell the Entity Framework which properties you are going to use in advance and it will load them in one call from the database.

      Query c = ctx.Queries
      .Include(x => x.Derived)
      .Include(x => x.Base).First();

    Here you use the Include method to tell the Entity Framework to load both your Derived collection as your Base property.

    • Use lazy loading. This means that the Entity Framework will load your property when it’s needed. For this to work, EF creates a proxy class that wraps your class and will execute the database calls just in time.

      For this to work, you will need to declare your public SomeType Base { get; set; } as virtual so EF can create a proxy and intercept those calls.

    The only reason you where not seeing your data, is because it wasn’t loaded from the database.

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

Sidebar

Related Questions

I am building a website templating system where multiple user can create their own
I am building a website that would serve dynamic content. All communication between server/browser
I am building a website which includes a full width slider; 100% of browser
I'm building a website in ASP.net and using a database in mysql. Now I
I'm building a website that prints the content in it's Mysql database to the
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I am building an image upload function for my website and rather than waste
I have zero experience building website with Java. Recently I need to develop complex
Building a website that has English & Japanese speaking users, with the Japanese users
I am building a website to capture data. I have many spreadsheets that are

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.