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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:59:52+00:00 2026-05-29T06:59:52+00:00

I have a component on an entity that may be null. This works in

  • 0

I have a component on an entity that may be null. This works in a unit test with an InMemory database, but does not work on a file based SQLite database.
I use a boolean flag to indicate whether the component was set, but this seems to be a hack.

Is this a NHibernate or a SQLite Bug? Or am i missing something?

Here are my mappings stripped of business value:

public sealed class EntityMap : ClassMap<Entity>
{
   public EntityMap()
   {
     Not.LazyLoad();
     Id(m => m.Uid);
     Map(m => m.HasComponent).Not.Nullable();
     Component(m => m.Component).ColumnPrefix("Component");
   }
}

public sealed class MyComponentMap : ComponentMap<MyComponent>
{
   public MyComponentMap()
   {
     Map(c => c.SomeBasicProperty).Nullable();
     HasMany(c => c.ListOfValues).AsList(li => li.Column("Number"))
                           .Component(part => 
                                         {
                                             part.Map(s => s.Name);
                                             part.Map(s => s.Value);
                                         }
                            .Table("ComponentValues")
                            .Cascade.AllDeleteOrphan().Not.LazyLoad();

   }
}

With the memory database the component on the entity is null when all columns for it are null. This is what i expect.
When using a file based database the component is empty. So i cannot use entity.Component==null to check if the Component has already been set.

  • 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-29T06:59:53+00:00Added an answer on May 29, 2026 at 6:59 am

    i tested your code with inmemory and it returns Component != null for an inmemory database as expected. In NHibernate a collection is never null but can be empty and a component is only null if all properties are null hence the component should never be null. i guess that you tested like

    using (var tx = session.BeginTransaction())
    {
        id = session.Save(new Entity());
        tx.Commit();
    }
    
    var entity = session.Get<Entity>(id);
    Console.WriteLine(entity.Component == null);
    

    Get returns the same instance which has Component set to null.

    using (var tx = session.BeginTransaction())
    {
        id = session.Save(new Entity());
        tx.Commit();
    }
    
    session.Clear();
    
    var entity = session.Get<Entity>(id);
    Console.WriteLine(entity.Component == null);
    

    Get returns the loaded instance which has Component set to non-null.

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

Sidebar

Related Questions

I have a component that i want to store to an SQLite database. public
I have an entity that is mapped with a <join> element like this: <class
I have a 'User' Entity that contains an 'Address' Value Object. I have this
I have a mapped entity, Matter, that has a mapped component, Injury. The only
I have a component which writes/generates javascript from a server side renderer. This component
I have a component that I hand over a function public var func :
I have a component that is made up of various components such as a
I have a component where i want to display a custom jtooltip. That is
I have a component with a number of properties that have various attributes Normally
I have a component called a TableDataViewer that contains the following pieces of data

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.