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
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.
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:
or this