Fluent NHibnerate CheckReference throws Expected ‘X’ but got ‘XProxy’

· September 8, 2009

I have been playing around quite a lot with Fluent NHibernate lately and ran into this problem a couple of times.

What happens is that when you set up a mapping test with PersistenceSpecification<T> that tests a reference (with CheckReference for example), an exception is throw like this:

System.ApplicationException: Expected ‘Marcusoft.Product’ but got ‘ProductProxy…’ for Property ‘Product’

This has to do with that NHibernate creates a proxy-class and doing Equality-test on that class. I have picked up a base class that “fix” this problem from the Hibernating Rhinos (my god! what a name…)

You can read about it here or read my code here.

Twitter, Facebook