Hi everyone,
I'm relatively new to NHibernate, but I'm a graduate computer scientist and
after nearly a whole day of searching for an answer to my problem, I'm
asking myself
*"How can this be so hard!?"*
I have multiple classes, say class A and class B, where A has an instance
of B as property like
public class A : SomeBaseClass
{
virtual public Int64 ID {get; set;}
virtual public string foo {get; set;}
virtual public B my_B_instance {get; set;}
}
public class B : SomeBaseClass
{
virtual public Int64 ID {get; set;}
virtual public string bar {get; set;}
}
as you might notice, B does NOT have a reference to an A.
Now I want to map the classes. First I tried something like
<property name="my_B_instance"/>
because the Getting Started
Tutorial<http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx>is
too damn busy confusing the NHibernate tutorial for an NUnit tutorial
(and getting me confused about which code is for NHibernate and which code
is for NUnit) to mention that "property" is only for primitive types.
It took me hours to figure out why I got all the "Could not determine the
type of ..." exceptions!
So with far too much googeling, I found out, that
<one-to-one .../>
should be the answer, BUT before even trying this, I found that one-to-one
mappings must be bidirectional (so B would HAVE TO have a reference to an
A).
In my project, A=Person, B=Address and other classes like Subsidiary also
have an Address, so referencing Person in Address would be complete
nonsense.
I got lost in the 500 page list of
options<http://nhforge.org/doc/nh/en/index.html>
Other "solutions" i have found, suggest using composite-id's or that my
classes should implement IUserType. In both cases I would have to override
the methods that NHibernate calls.
I will not do that, because handling a *fundamental* thing like a reference
to one class as property of another class CAN NOT BE SO HARD!
And I haven't even started looking into inheritance. God have mercy on my
soul!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/ocaC5W0CZtgJ.
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.