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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:03:25+00:00 2026-06-04T23:03:25+00:00

I currently have an issue when updating a component collection on an entity. It

  • 0

I currently have an issue when updating a component collection on an entity. It was originally mapped as a bag but that was causing all entries to be deleted and reinserted each time. Changing it to a set has fixed that problem but introduced a new one.

The component type is called Tracking it has a composite key of UserID and ItemID and two properties which are nullable dates. When one of these is created DateRead set to the current time, it is then replaced later with an entry with the new date on.

The underlying SQL NHibernate generates has a where clause which checks that all properties match.

The issue is, the other date DateAcknowledged is often null, and the generated SQL seems to have a syntax error, to do a null check its doing this: = NULL rather than: IS NULL, as shown:

DELETE FROM TrackingTable
   WHERE  ItemId = 'a68f6dea-1c00-42e2-bc40-9fcf01121bd8' /* @p0 */
   AND UserId = 'c8aa41a4-e4c2-4347-ae6e-b48738a53b47' /* @p1 */
   AND DateRead = '2012-01-26T12:56:46.00' /* @p2 */
   AND DateAcknowledged = NULL /* @p3 */

The thing is, the two dates should not be needed at all to determine what to delete. Simply having the where check item ID and user ID would do.

Here is the mapping code where I define the set:

Set(x => x.Trackings,
         mapper =>
                {
                    mapper.Key(k => k.Column("ItemId"));
                    mapper.Table("Tracking");
                    mapper.Access(Accessor.NoSetter);
                },
                collectionMapping => collectionMapping.Component(TrackingMap.Mapping()));

And here is the mapping for the component:

public class TrackingMap
    {
        public static Action<IComponentElementMapper<Tracking>> Mapping()
        {
            return c =>
            {
                c.ManyToOne(x => x.User, a => { a.Column("UserId"); a.ForeignKey("UserId"); });
                c.Property(x => x.DateRead);
                c.Property(x => x.DateAcknowledged, a => a.NotNullable(false));
            };
        }
    }

Is there a way to tell NHibernate to use the keys only on the where clause or for it to compare nulls in the correct way?

  • 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-06-04T23:03:27+00:00Added an answer on June 4, 2026 at 11:03 pm

    This is covered by section 7.2. Collections of dependent objects which notes that this is not supported:

    Please note that a composite element mapping doesn’t support null-able properties if you’re using a <set>. NHibernate has to use each columns value to identify a record when deleting objects (there is no separate primary key column in the composite element table), which is not possible with null values. You have to either use only not-null properties in a composite-element or choose a <list>, <map>, <bag> or <idbag>.

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

Sidebar

Related Questions

I currently have a issue with firefox, where all other browser behave in the
I currently have an issue with my URI's Example I have a function called
I'm having an issue with multiple markers on google maps - I currently have
Okay so I have encountered a frustrating issue with namespaces. I am currently using
I have a WPF ListView that is bound to a collection ( List<T> ).
I have an issue about Entity Framework 4 CTP 5, which I realize LINQ
i currently have highcharts realtime graph working on a browser (e.g. http://www.highcharts.com/demo/dynamic-update ), but
I currently have a program that runs several intense queries. I added a textbox
So here is the issue, I have 6 divs that are using jQuery UI
I have a question that involves a performance question and Mongo Design. Currently a

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.