The NHibernate documentation clearly states that  "NHibernate treats 
unidirectional one-to-many and many-to-many associations owned by a 
read-only entity the same as when owned by an entity that is not read-only."

*My question is:  Why?*

If I loaded an object as readonly, I would expect all of its collections to 
be readonly and not dirty checked.  Why did nHibernate decide to not 
implement it this way?


I ask this because of a project I've inherited has issues with unnecessary 
SELECT statements happening when a session transaction closes.  I 
discovered this was because the object in question had a lot of child 
collections where the getter called a function on the underlying data 
(self-changing entities) to mitigate an issue where nhibernate inserts null 
objects into lists with a index field where there's a gap in the index .  I 
understand the right way to fix this is to not to call a function on the 
getter, but I was trying to avoid that by calling the parent object as 
read-only.

But also, in these cases, I *know* I am only loading the parent object to 
access data and I am not changing it.  I don't need NHibernate to check if 
it's dirty, I know it's not, similar to using AsNoTracking() in Entity 
Framework.

So, back to the question:  Why was NHibernate implemented this way?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/c605b3f5-6fd0-4fe1-a9a7-04d3de5e3ec4n%40googlegroups.com.

Reply via email to