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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:46:53+00:00 2026-06-06T19:46:53+00:00

I have two classes and mapping for the collection: class User { Guid ID;

  • 0

I have two classes and mapping for the collection:

class User
{
    Guid ID;
    string Name;
}

class Group
{
    Guid ID;
    string Name;
    IList<User> Members;
}

// GroupMap
HasMany(x=>x.Members).Inverse().Cascade.AllDeleteOrhpan().etc.

This one works. When I add a User to the Members collection NHibernate cascades the operation. Same for deletes and updates.

Now I want to change my model a bit and this will change also the mapping. The collection is IList<Guid>. What I really want is the cascade to remain. That means that I have to do some custom persister or IUserType. The mapping should tell the object type like HasMany(x=>x.Members) and the collection will hold the IDs

class User
{
    Guid ID;
    string Name;
}

class Group
{
    Guid ID;
    string Name;
    IList<Guid> Members;
}

// GroupMap
HasMany<User>(x=>x.Members).Inverse().Cascade.AllDeleteOrhpan().etc.

Any ideas where can I start from? I think that there is no out of the box solution but who knows…

PS: NHib user group: https://groups.google.com/forum/#!topic/nhusers/pSUOaGxdxVM

  • 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-06T19:46:54+00:00Added an answer on June 6, 2026 at 7:46 pm

    For the 1st comment: The custom persiter or something else should take care about backreference.

    so the first mapping doesnt really work already? You could map a virtual backreference on User and set it through an interceptor, i can post something if needed. However i hardly see any advantage.

    For the 2nd: Group and User are two aggregate roots. I want to connect the two ARs only by their identity. The two ARs do not need any other information except the other’s ID.

    // readonly mapping
    HasMany(x => x.Members).Column("Group_Id").Element("Id").Readonly();
    

    I think you will run into a lot of subtle problems when you have a non readonly collection of guids pointing to Users. For example what sql should be generated for:

    var user = new User { Id = Guid.New(), Name = "Joe", Age = 12 };
    group.Members.Add(user.Id);
    
    session.SaveOrUpdate(group);
    session.Flush();
    
    a) INSERT INTO Users (Id, Group_id) Values(...);
    b) nothing
    c) INSERT INTO Users (Id, Group_id, Name, Age) Values(...);
    

    or this

    group.Members.Remove(someGuid);
    
    session.SaveOrUpdate(group);
    session.Flush();
    
    a) DELETE FROM Users WHERE group_id = 1;
    b) DELETE FROM Users WHERE id = <guid>;
    c) Update Users Set group_id = null WHERE Id = <guid>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two domain classes: User : class User { String login String password
I have two domain classes: class Domain1 { String val11 String val12 Domain2 domain2
In nhibernate, I have two classes that are associated with a many-to-one mapping: <class
Scenario 1: I have two classes: Post : class Post { String content Date
I have two classes with a bi-directional @OneToOne mapping to each other. Class A
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, one that inherits from the other. The base class is
I have two classes set up as follows: class Point { protected: double coords[3];
I have two classes like so: public class SentEmailAttachment : ISentEmailAttachment { public SentEmailAttachment();

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.