The situation is the following.
I've a recipient class hiearchy like this:
RecipientA(abstract)
RecipientB:RecipientA
RecipientC:RecipientA
Inheritance mapping is: Table per subclass.
I also have a class which holds a communication entity. This
Communication class has
a property of type RecipientA (named as Sender) and a property of type
string named as SenderName.
public class Communication
{
public virtual RecipientA Sender{get; set;}
public virtual string SenderName{get;}
}
SenderName ppty checks whether the Sender ppty is type of RecipientB
or RecipientC and gets
the appropriate value from the casted Sender object.
In the application I run a query for communication objects (with
ISession.CreateQuery()) and
I'm trying to bind the mentioned SenderName property of each
communication object to the UI.
PROBLEM:
After the CreateQuery() - which lists for me the requested
Communication objects from DB -
all of the Communication objects in the list are holding a
RecipientAProxyXXXXXXXX type entity
in their Sender property instead of an expected RecipientB or a
RecipientC type object.
I've created a simple "test" to examine the behaviour. I've ran it two
different ways:
FIRST:
...
//Load the communication which holds a RecipientC type object as
Sender
Communication communication = session.Get<Communication>(6622);
session.Evict(communication);
//Load the RecipientC type object itself with ISession.Get
RecipientA recipient1 = session.Get<RecipientA>(19668);
session.Evict(recipient1);
//Load the RecipientC type object itself with ISession.Load
RecipientA recipient2 = session.Load<RecipientA>(19668);
session.Evict(recipient2);
...
RESULTS (from quick watch):
communication.Sender ID = 19668 RecipientA
{RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
recipient1 ID = 19668 RecipientA
{RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
recipient2 ID = 19668 RecipientA
{RecipientAProxy19bff2639c8b4870a36fc8a968ed5578}
None of the above types are good for me as I expected a RecipientC
type for communication.Sender and for recipient1.
SECOND:
...
//Commented out to check behaviour
//Communication communication = session.Get<Communication>(6622);
//session.Evict(communication);
//Load the RecipientC type object itself with ISession.Get
RecipientA recipient1 = session.Get<RecipientA>(19668);
session.Evict(recipient1);
//Load the RecipientC type object itself with ISession.Load
RecipientA recipient2 = session.Load<RecipientA>(19668);
session.Evict(recipient2);
...
RESULTS:
recipient1 ID = 19668 RecipientA {RecipientC}
recipient2 ID = 19668 RecipientA
{RecipientAProxy0df492d12da94359a34b5e79edc08cf9}
I this second case recipient1 has the expected type it can be cast to
RecipientC.
How should I handle this? I need to access the SenderName ppty as
RecipientB or RecipientC after a query.
Why NHibernate loads it as a RecipientAProxy on the communication?
I'm currently migrating to NHibernate 2.0.1GA and the old version that
I've used worked as expected.
I've tried it with several inheritance mapping strategies (Table per
class, Table per subclass using a discrimiator etc.) the results
always were that I've described here.
The only solution looks like for now is to turn off lazy loading on
these entities which is not acceptable.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---