Hi guys,

The way I understand it with Bags is that NHbernate cannot fire 
PreCollectionUpdateEvents for these as it has to delete the whole 
collection (as one large delete) and then add each row individually 
afterwards as per the docs:

'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.'

This is the behaviour that I can see happening in these 2 maps. I am using 
Fluent NHibernate to map which defaults to Bag for these HasMany types, I 
can confirm that in the first two map cases it does delete (it actually 
orphans without delete) and recreate the whole collection, without firing a 
PreCollectionUpdateEvent.

So here are the first 2 maps which do not fire PreCollectionUpdateEvents, 
only deletes and inserts on collection changes:

            HasMany(x => x.Class1)
                .Cascade.All()
                .Access.BackingField();

            HasMany(x => x.Class2)
                .Table("Class2")
                .KeyColumn("Parent_id")
                .Inverse()
                .Cascade.AllDeleteOrphan();

However, a second map that I have which to me appears to follow the same 
(well, similar) format, but this fires a PreCollectionUpdateEvent and not a 
delete followed by multiple inserts as I would expect. I can't see a common 
difference between the three that I can see mattering...I can say that 
Class1 and Class2 have maps of their own, and both reference the Parent, 
but in the following case Class3 is of Type String, so needs no Map.

            HasMany(x => 
x.Class3).Table("Class3").Element("Class3Elem").Cascade.All();

I wonder if anyone can throw some ideas out there as to why this might be? 
I can provide more information if needed, I believe the table constraints 
are irrelevant as since it's mapped as a bag NHibernate will not check? The 
types of Class 1, 2 and 3 are all mapped to IList properties of their 
respective Type.

Thanks,

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to