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 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 am using Rails 3.2. I have following models: Blog Comment User class Blog
Suppose I have a Comment class having properties and their methods like public Comment
I have a Comment class with a :foreign_key of post_id in the Post class.
I have a Post Class and a Comment Class. I have a post object
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I hope I am clear enough. My data set is populated I have comment:CommentVO;
I have an Item class and a Comment class. Items have many embedded comments.
I have a domain model that includes something like this: public class Customer :
class Comment < ActiveRecord::Base belongs_to :post belongs_to :user end So with the above association
I have a couple of objects in a Rails app (Ticket, and Comment) class

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.