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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:03+00:00 2026-05-27T04:26:03+00:00

I am using NHibernate with a NullObject pattern to make my views simpler. I

  • 0

I am using NHibernate with a NullObject pattern to make my views simpler.
I use a solution found here by James Gregory

public Address GetAddressOrDefault()
{
  return Address ?? new NullAddress();
}

And Person has an Address property and so on….

This is working very good until I try to save my Person object for a person without an address. Since I created a new instance of the NullPerson object, NHibernate will try to save it. And gives me this:

ids for this class must be manually assigned before calling save():

Is there any way I can get NHibernate to not try to save my NullObjects? Or is there any other way I should be attacking this?

  • 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-27T04:26:04+00:00Added an answer on May 27, 2026 at 4:26 am

    I know you’ve probably considered this but simplest solution seems to be to the reverse of

    public Address GetAddressOrDefault()
    {
      return Address ?? new NullAddress();
    }
    

    ie, prior to your save call:

    public Address GetAddressOrNull(Address address)
    {
      return address is NullAddress ? null : address;
    }
    

    Or…You might consider using a dedicated class for your ViewModel if things get more complex and using AutoMapper to do the monkey work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I am using NHibernate as my ORM solution and have a need for a
I'm using NHibernate 3.2 and I have a repository method that looks like: public
I am using nhibernate to map the following classes: public class DeviceConfig : EntityBase
I'm using NHibernate -driven repository, Fluent mappings and attempt to use Linq to NHibernate
I'm using NHibernate, DI/IoC and the Unit of Work pattern. Most UoW examples I've
I would like to make use of the Null Object pattern in my domain,
Using NHibernate, how can I map the following scenario: public class User { public
I'm using NHibernate and looking for a solution that will allow me to audit
I'm using NHibernate 3.2 and have the following model: class User { public virtual

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.