I've been trying to implement the following scenario with nhibernate
The class types and names have been changed for simplicity's sake
Lets say i have entity type
Person
and a component type
Address
the class structure looks similar to the following
Person
WorkAddress
CurrentHomeAddress
PermanentAddress
ShippingAddress
BillingAddress
Address
Street
Number
City
ParentEntity
my real domain has many more entities and many more components(value
objects) (or what should be components)
the inheritence hierarchy for both entities and components are pretty
complex and deep, and there are more properties per inheritance level, so
treating it like a true NH component (where all component properties reside
in the same table as entity) starts becoming unfeasible (too many columns,
lots of nulls, not normalized schema etc)
i want to be able to correctly map, save and load person/address,
Currently i have the domain treating address as a value object, but
nhibernate treating it as an enitity (so it will save address to another
table)
The join table feature seems like it would really make things easier,
especially join component, and set component mapping parent property
this is what i tried:
public class TestJoinComplexPropertyMap : ClassMapping<ParentOfOneToOne>
{
public TestJoinComplexPropertyMap()
{
this.Join("ComplexPropertyOneToOne1", j =>
{
j.Component(
one => one.OneToOne1
, c =>
{
c.Parent(cp => cp.Parent);
//c.Unique(false);
}
);
j.Table("ComplexPropertyOneToOne");
j.Fetch(FetchKind.Join);
j.Inverse(true);
j.Optional(true);
j.Key(k =>
{
k.NotNullable(true);
k.OnDelete(OnDeleteAction.Cascade);
k.Unique(false);
k.Update(true);
k.PropertyRef(parented => parented.OneToOne1);
});
});
}
}
however, even though address is a component, instead of the address table
containing the parent person's id, address would need to have its own Id,
with person having WorkAddressID, CurrentHomeAddressID etc.
thus its not a strict one-to-one relationship
(in our domain, person has 5 addresses and will only ever have 5 addresses,
so having a collection is not necessary.... even more so, as you'll see
below, some entities may have only one, or two addresses)
note, having workaddressStreet, workAddressNumber,
currentHomeAddressStreet, CurrentHomeAddressNumber etc all as columns in
the address table is not feasible as the are many properties that are of
type address, (and as you'll see below, many other entities also have
address properties)
trying to do join table with a component property doesn't seem to give me
correct save / load behaviour (even after fiddling around with some of the
mapping parameters)
my current implementation has a many to one from parent to child
component/entity, and a many to one from child component/entity to parent,
where the parent property is persisted as well
this results in excessive joins
(parent1 join child1
on parent1.childpropid = child.id
join parent2
on child.parentid = parent2.id..... parent1 and parent 2 return the same
row)
Is it possible to use table join component for a scenario like this
if so consider also the following entity
Company
HeadQuarterAddress
WarehouseAddress
CustomerCentreAddress
ShippingAddress
BillingAddress
there are many entities as well with address type properties
is it possible to still do join table component and specify parent property
Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.