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

  • Home
  • SEARCH
  • 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 8214665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:31:55+00:00 2026-06-07T11:31:55+00:00

I have a very simple object models. public class Contact { public virtual int

  • 0

I have a very simple object models.

public class Contact
{
    public virtual int Id                { get; set; }
    public virtual string Name           { get; set; }
    public virtual Device Device         { get; set; }
    public virtual IList<string> Numbers { get; set; }

    public Contact()
    {
        Numbers = new System.Collections.Generic.List<string>(3);
    }
}

As you can see, the class Contact has an association with Numbers, which is a list of strings.

Here’s the mapping:

        Id(x => x.Id).GeneratedBy.Assigned();
        Map(x => x.Name);
        References(x => x.Device, "DeviceId");
        Table("Contacts");
        HasMany(x => x.Numbers)
            .Table("ContactNumbers")
            .Element("Number")
            .KeyColumn("ContactId")
            .LazyLoad()
            .Cascade.All()
            .Not
            .Inverse();

Note that I can’t and don’t want the collection to be inverse=true, because it’s just a collection of string. This means that Contact is responsible for updating Numbers entries.
Now my problem is that, whenever I try to add a new number to an existing Contact, it deletes all associated numbers and recreates them individually. Isn’t NHibernate smart enough to detect changes and update only changed items?

I think there should be a simple solution for my problem but don’t know what.

Any help would be appreciated.

  • 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-07T11:31:56+00:00Added an answer on June 7, 2026 at 11:31 am

    This is actually documented in NHibernate’s documentation.

    Bags are the worst case. Since a bag permits duplicate element values
    and has no index column, no primary key may be defined. NHibernate has
    no way of distinguishing between duplicate rows. NHibernate resolves
    this problem by completely removing (in a single DELETE) and
    recreating the collection whenever it changes. This might be very
    inefficient.

    Try using an <idbag> mapping instead, and create a surrogate primary key for that table. Unfortunately, looks like <idbag> is not yet supported in FluentNHibernate.

    Also, take a look at other collection mapping options.

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

Sidebar

Related Questions

Given a very simple object: class User { private Integer id; private String name;
I have a very simple method: Class Team(models.Model): def sides(self): return SideNames.objects.filter(team=self) SideNames is
I have a very simple composite model made of two classes: Public Class ParentModelVM
I have a public class called Profile . Very simple model class currently with
I have a very simple array (please focus on the object with "points.bean.pointsBase" as
I have a simple Android OpenGL-ES app, and as all the models are very
I have a very simple viewmodel class, and a strongly typed view (which uses
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple window where I have 2 buttons - one for cancel,

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.