Hi,
I've been at this for the last 3 days and still can't figure it out.
Conceptually I need to design an envelope object and its to and from
addresses (object). I have the following database schema (which I cannot
change):
Table Envelope
- EnvelopeId (PK)
- PostmarkDate
Table Address
- EnvelopeId (PK, FK in Envelope)
- AdressType (1 - for From addresses, 2 - for To addresses)
- Street
- State
- ZipCode
*unique contraint on (EnvelopeId, AdressType)
My classes are as follows:
public class Envelope
{
public virtual long EnvelopeId { get; set; }
public virtual DateTime PostmarkDate { get; set; }
public virtual Address FromAddress { get; set; }
public virtual Address ToAddress { get; set; }
}
public class Address
{
public virtual AddressId { get; set; }
public virtual Envelope Envelope { get; set; }
public virtual AdressType { get; set; }
public virtual Street { get; set; }
public virtual State { get; set; }
public virtual ZipCode { get; set; }
}
So, Envelope ends up having 2 corresponding Address entries (with it's
primary key): one with AddressType 1 and one with AddressType 2. I haven't
included my mapping files because that's where the problem lies. I
attempted several solutions:
1. a one-to-one relationship between Envelope and Address. I had 2
one-to-one tags in the Envelope mapping file, and a one-to-one tag in the
Address mapping file. The Address mapping file also had a foreign generator
and a constrained="true" on Envelope. NHibernate complained that the
one-to-one mappings between Envelope and Address was confusing.
2. created 2 classes FromAddress and ToAddress, both derived from Address.
Envelope class now had a FromAddress and a ToAddress (instead of 2
Address). I implemented table-per-class hierarchy for the inheritance. In
my Address mapping I had: a foreign generator, 2 subclass tags,
discriminator values and a one-to-one relationship to Envelope. But
NHibernate complained about not liking the discriminator and the one-to-one
together. So then I moved the one-to-one tag inside the subclass tags. Now
NHibernate complained about not knowing what the Envelope property is
("Unable to resolve property: Envelope")
Any help would be appreciated.
Thanks,
Tiberiu
--
---
You received this message because you are subscribed to the Google Groups
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.