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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:18:53+00:00 2026-05-15T22:18:53+00:00

I’m working with an old database used by other applications, so i can’t modify

  • 0

I’m working with an old database used by other applications, so i can’t modify its structure.
Sometimes i have nullable columns that i want to map as a non nullable type.
For instance I have a nullable EndValidity column on database which i want to map on a non nullable DateTime, and, if null, it should be DateTime.MaxValue, or as a more simple example, a nullable bit column that must be false if null.

I’m thinking about writing a custom user type for it (with parameters if possible), or is it there something included in nHibernate for it?

If the only solution is to write a custom usertype, for the boolean case, can I override fluentnhibernate conventions to always apply that usertype for booleans?

  • 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-15T22:18:54+00:00Added an answer on May 15, 2026 at 10:18 pm

    It probably depends on how you want your poco class you act.
    Firstly if you load a null value do you want the null value to be re-saved or do you want any session commit/flush to update the record with the new default for the null field.
    If you want to keep the null value in the DB how would you detect from your poco object with just a boolean which value to save IE booleans have only true and false options / values but your bit class has the options / values of null, 0 and 1?

    If say: you want to have your nullable bits as a boolean and not a nullable boolean dataype in your poco class and have the class update the db to remove all the nulls then one solution which is pretty quick without diving into custom types is to have the two properties one nullable and protected or internal and one property in an interface ( without any mapping ) with basic logic – for reasons of dependancy injects all poco classes would ideally have an interface or two:
    EG

    internal virtual bool? isActive {get;set;}
    public bool MyInterface.IsActive 
    {
        get{ return isActive ?? false; }
        set{ isActive == value ?? false; };
    }
    

    This way your logic is contained in code so if the rules get more complex/complicated or one nullable bit has a default of false but another has a default of true ( because of some insane developer from last century ) you can more easily control the transformations.
    It will require you working with interfaces instead of the real poco classes, but again this isn’t a bad thing, it just depends on your development model.

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

Sidebar

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.