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

  • Home
  • SEARCH
  • 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 4322378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:51:56+00:00 2026-05-21T08:51:56+00:00

I have a Comment class with, among others, an Author property: public class Comment

  • 0

I have a Comment class with, among others, an Author property:

public class Comment : IEquatable<Comment>
{
    public int ID { get; set; }

    [Required]
    public virtual User Author { get; set; }

    // More properties here
}

I want users to be able to “like” a comment, much like here at StackOverflow. To that end I have the following action in my CommentController:

public virtual ActionResult Like(int id)
{
    var comment = _session.Single<Comment>(c => c.ID == id);
    comment.Likes++;

    _session.CommitChanges();

    return Json(new { comment.Likes });
}

Whenever I invoke this action I get the following Validation Error:

The Author field is required.

The Comment object comes from the db, so it does have an author. The “funny” thing is, whenever I use the Visual Studio debugger to check whether the Author really is missing, the validation error does not fire.

Am I correct in assuming here that the problem is that the lazy loading of the Author property never takes place? If so, how can I, for this situation only, force all navigation properties to be filled in? (I want to keep working with lazy loading otherwise)

What’s the neatest way to solve this? Am I even on the right track?
And why isn’t lazy loading happening while EF clearly requires it to save the entity?

Any help will be 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-05-21T08:51:57+00:00Added an answer on May 21, 2026 at 8:51 am

    You could use Include to eagerly fetch a relation on the data context.

    context.Comments.Include("Author").Single<Comment>(c => c.ID == id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of objects in a Rails app (Ticket, and Comment) class
I have created a DisplayTemplate for a Comment class, and placed it inside Comment/DisplayTemplates/Comment.cshtml
In order to reference a member of a class in XML comments/documentation, you have
I have to store blog style comments in a database. Each comment can have
The common sense tells that the Doxygen comment blocks have to be put in
I have been making a threaded comment system as a way to learn php
I have a page that is generated which inserts an HTML comment near the
I have an xml file where I need to comment out a whole piece
Let's say I have two tables: Report Comment And assuming I have a database
I have a table called BlogPost which has a 1-to-many relationship with the Comment

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.