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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:09:04+00:00 2026-06-13T07:09:04+00:00

I’m trying to create a site with news that can have comments. I’ve been

  • 0

I’m trying to create a site with news that can have comments. I’ve been following guides from pluralsight.com and I’ve followed what is done in the guide to the letter but when i debug and look at what’s inside the model at runtime the comments aren’t included.

My DB class:

public class ProjectDB {
        public DbSet<ContentNode> ContentNodes{ get; set; }
        public DbSet<Comment> Comments { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<ContentNode>()
                .Property(n => n.ID).HasColumnName("NodeID");
            modelBuilder.Entity<ContentNode>()
                .HasMany(node => node.Comments)
                .WithRequired(comment => comment.Node);
        }
}

The models involved:

    public class ContentNode : Node
    {
        public ContentType ContentType { get; set; }
        public ContentCategory Category { get; set; }
        public ICollection<Comment> Comments { get; set; }

        public ContentNode()
        {
            Comments = new List<Comment>();
        }
    }

    public class Comment
    {
        public int ID { get; set; }
        public ContentNode Node { get; set; }
        public string Body { get; set; }
    }

The controller method that pulls the news article from the db and sends it to the view

[GET("frettir/{year}/{month}/{day}/{title}")]
public ActionResult GetArticle( int year, int month, int day, string title)
{
    var model = (from f in _db.ContentNodes
                 where f.dateCreated.Year == year &&
                       f.dateCreated.Month == month &&
                       f.dateCreated.Day == day &&
                       f.Title == title &&
                       f.ContentType.ID == 1
                 select f).Single();

    return View(model);
}

And finally the view itself:

@model Project.Models.ContentNode

@{
    ViewBag.Title = "GetByID";
}

<h2>GetByID</h2>

<fieldset>
    <legend>News</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Title)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Title)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Body)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Body)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.dateCreated)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.dateCreated)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.ID }) |
    @Html.ActionLink("Back to List", "Index")
</p>

    @foreach (var item in Model.Comments)
    {
        @Html.Partial("_Comment",item)
    }

@Html.ActionLink("New comment", "Create", "Comment", new { NodeID = Model.ID }, null)

I’ve looked at examples and I’ve looked over the video guide a dozen times to see what i did wrong. The only solution that I’ve come up with is joining the NodeContent table with the Comments table and projecting it into another model but from what i can gather that shouldn’t be required.

Any help is appreciated.

  • 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-13T07:09:05+00:00Added an answer on June 13, 2026 at 7:09 am
    var model = _db.ContentNodes
        .Include(f => f.Comments) // eager load the child collection
        .Single(f => f.dateCreated.Year == year 
             && f.dateCreated.Month == month
             && f.dateCreated.Day == day 
             && f.Title == title 
             && f.ContentType.Id == 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put

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.