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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:33:05+00:00 2026-05-11T22:33:05+00:00

I’m having a problem with Fluent NHibernate mappings, I think, and can’t quite get

  • 0

I’m having a problem with Fluent NHibernate mappings, I think, and can’t quite get past how I should be setting the mapping to avoid an issue.

I have a business object (literally, a “business”), and a review object. Each Business can have multiple reviews that are created on a page in the UI. The business is a property of the Review, as follows:

public class Business 
{
    public virtual int BusinessId {get;set;}
    public virtual DateTime LastModified {get;set;}
    public virtual IList<Review> Reviews {get;set;}

    [... more removed for brevity ...]

}

public class Review
{
    public virtual int ReviewId {get;set;}
    public virtual string ReviewText {get;set;}
    public virtual Business Business {get;set;}

    [... more removed for brevity ...]

}

My mappings are as follows:

public class ReviewMap : ClassMap<Review>
{
    public ReviewMap()
    {
        WithTable("Reviews");
        Id(x => x.ReviewId).TheColumnNameIs("ReviewId").GeneratedBy.Identity();

        References(x => x.Business).TheColumnNameIs("BusinessId");

        Map(x => x.ReviewText);

       [... and so on...]
}


public class BusinessMap : ClassMap<Business>
{
    public BusinessMap()
    {
        WithTable("Businesses");

        Id(x => x.BusinessId).TheColumnNameIs("BusinessId").GeneratedBy.Identity();

        Map(x => x.Name).TheColumnNameIs("BusinessName");
        Map(x => x.LastModified, "LastModifiedOn");

        HasMany<Review>(x => x.Reviews)
            .Inverse()
            .LazyLoad();

        [... more removed for brevity ...]

    }
}

The repository code is

public void Save(T entity)
    {
        using (ISession session = GetSession())
        using (ITransaction tx = session.BeginTransaction())
        {
            session.SaveOrUpdate(entity);
            tx.Commit();
        }
    }

In the code, I assign the properties to the Review object, and call the Repository’s Save method.

The problem is that since I’m not updating the Business per se, I don’t expect it to get saved–all I want is the review saved. But the code tries to save the Business as well, and I get an excption, as I haven’t set the “LastModified” property–nor do I want to, as I’m saving the REVIEW, not the business.

How should I be setting up the mapping to let this happen?

  • 1 1 Answer
  • 3 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-11T22:33:05+00:00Added an answer on May 11, 2026 at 10:33 pm

    Ok, so the problem was this: the Business’s LastModified property wasn’t actually set in the actual business object, as the database allowed NULL for this property.

    What that meant was that when I tried to save the review, it also tried to save the business–most likely because it recognized that the database object had no value (null) for LastModified, but by default, since LastModified is a DateTime, its value was DateTime.MinValue.

    Once I updated the business table in the database so that LastModified is now NOT NULL, it works.

    The unfortunate part of this is that the data I was working with got into this state without this being an issue.

    • 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
I have a jquery bug and I've been looking for hours now, I can't
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
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.