I have not found a solution for this. Furthermore I experience additional issues when using proxies with nhibernate. For example, given the example classes above, you can get errors when doing something like this
var foo = session.Get<Foo>(10); var bars = session.CreateCriteria<Bar>().List<Bar>(); If the first example loads foo and foo.Bar as a proxy and the same session is then used again in example 2 it can cause an exception. The criteria query will return all bar classes but will resolve things out of the session if it can. This means the bar which was proxied for the first query and put in the session will be resolved. When it comes to the List<Bar> an exception will occur as you cannot put INhibernateProxyProxy into the a list of type Bar. I experienced this issue yesterday, the only two solutions I can think of are: 1 - use session.CreateCriteria<Bar>().List() so untyped values are returned. An extension method can be made to allow each element to be unproxied (I can't remember the NHibernate API method for this) and turned into a generic list of the given type. 2 - Don't use proxies. For me it is very unattractive to have to mark all properties AND methods virtual. If a class hierarchy exists then it very hard to understand what can and can't be overridden. It also means any class can be inherited from and fudged by someone else. This is not a big problem if you are working on a small application on your own or with one other person but if you are in a large team building relatively large software then to me this is a big deal. But it seems that the proxy support has not been entirely thought out. There are issues I also get with lazy / eager loading and I wonder what other issues I will encounter. On Oct 25, 2:48 pm, Joseph Lam <[email protected]> wrote: > This seems related:https://nhibernate.jira.com/browse/NH-2845 -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
