Hello everyone,
I am setting an application that deals with Parts and Components. Each Part
can be made from Components which themselves refer to a certain quantity of
a Part that is needed. For example Part “A” is made from 2 of Part “B” and 1
of Part “C”. I have modeled and mapped it this way:
public class Part
{
public virtual string PartId { get; set; }
public virtual string PartDescription { get; set; }
public virtual IList<Component> Components { get; set; }
}
public class PartMap : ClassMap<Part>
{
public PartMap()
{
Id(x => x.PartId).GeneratedBy.Assigned();
Map(x => x.PartDescription);
HasManyToMany(x =>
x.Components).Cascade.All().Table("PartComponents");
}
}
public class Component
{
public virtual int ComponentId { get; set; }
public virtual Part ParentPart { get; set; }
public virtual Part ComponentPart { get; set; }
public virtual double QuantityPer { get; set; }
public virtual IList<Part> WhereUsed { get; set; }
}
public class ComponentMap : ClassMap<Component>
{
public ComponentMap()
{
Id(x => x.ComponentId);
References(x => x.ParentPart).Column("ParentPartId");
References(x => x.ComponentPart).Column("ComponentPartId");
Map(x => x.QuantityPer);
HasManyToMany(x =>
x.WhereUsed).Cascade.All().Table("PartComponents");
}
}
This produces the following database schema:
*Part*
PartId
PartDescription
*Component*
ComponentId
QuantityPer
ParentPartId
ComponentPartId
*PartComponents*
Component_id
Part_id
After looking at the data it appears that the *PartComponents* table is
redundant because the *Component* table already satisfies the relationship
with the columns *ComponentId* and *ParentPartId*. Is there a way to map it
and remove the need for the *PartComponents* table.
Thanks,
Matthew
--
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.