GUZ
GUZ

Reputation: 647

NHibernate - Sequence numbers for child objects

In my business domain I need to do something with n-th child object which is inserted for a given parent object. So for examples some business actions should be invoked after inserting 100th, 200th and 300th child.

For now I have an idea to add a number field for children so the first child (for a given parent object) gets 1, the second gets 2, ... and so on. How may it be achieved using NHibernate? Or maybe there are better ways to achieve my goals.

Thank you in advance for answers and ideas.

Best regards Lukasz

Upvotes: 1

Views: 200

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

You can map your collection as a <list>... so the index of the children is stored.

Then you can use an AddChild method to add elements, so you can execute custom logic when you reach the n-th child.

Upvotes: 1

Related Questions