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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:31:32+00:00 2026-06-05T01:31:32+00:00

I’m having trouble getting all the data out of the database and I’m not

  • 0

I’m having trouble getting all the data out of the database and I’m not entirely sure what I’m doing wrong, pretty much all of this is new to me.

I’ve searched SO and found the following question which seems pretty similar to mine –
Repository Pattern for Entity Framework and Children Objects

I’ve looked at the answer which contained this link but I’m struggling to get this to work.

I have my campaign repository which returns a campaign. It returns the list of Audits as expected but the Audits don’t have the Comments or the CampaignAction in them. Is there something special I need to do to tell the DB to pull out all the cascading objects?

Thanks for any help

Neil

    public override Campaign Get(int id)
    {
        var query = Context.Campaigns.Include(x => x.Audits)
                                     .FirstOrDefault(c => c.CampaignId == id);
        if (query != null) 
            Logger.Trace(query.ToString());
        return query;
    }

I have my campaign class

public class Campaign
{
    public Campaign()
    {
        Audits = new Collection<Audit>();
    }

    public int CampaignId { get; set; }

    [StringLength(40, ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "CampaignModel_Name_StringLength")]
    [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "CampaignModel_Name_Required")]
    [Display(Name = "CampaignModel_Name", ResourceType = typeof(Resources.Resources))]
    public string Name { get; set; }

    public ICollection<Audit> Audits { get; set; }
}

And my audit class

public class Audit
{
    public Audit()
    {
        Comments = new Collection<Comment>();
    }

    public int AuditId { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "Audit_CampaignAction_Required")]
    [Display(Name = "Audit_CampaignAction", ResourceType = typeof(Resources.Resources))]
    public CampaignAction Action { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "Audit_UserName_Required")]
    [Display(Name = "Audit_UserName_Content", ResourceType = typeof(Resources.Resources))]
    public string UserName { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "Audit_TimeStamp_Required")]
    [Display(Name = "Audit_TimeStamp", ResourceType = typeof(Resources.Resources))]
    public DateTime TimeStamp { get; set; }

    public ICollection<Comment> Comments { get; set; }

    [JsonIgnore]
    public virtual ICollection<Campaign> Campaigns { get; set; }
}
  • 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-05T01:31:34+00:00Added an answer on June 5, 2026 at 1:31 am

    As long as you use eager loading, you have to call Include() on all entities, that you want to have loaded from database. This rule applies for child entities (Audits), but also for grandchilds (Action and Comments).

    Normally you would use simple dot-notation to include grandchilds, but if the child entity is a collection, there is a special syntax using the Select() method.

    Your query should look like

    var query = Context.Campaigns.Include(x => x.Audits)
                                 .Include(x => x.Audits.Select(a => a.Comments))
                                 .Include(x => x.Audits.Select(a => a.Action))
                                 .FirstOrDefault(c => c.CampaignId == id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

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.