I'm trying to map a new domain to a legacy db. here is the db
structure
Product (
ProductId
ReportName
)
ItemNum (
ItemNum
Item_Desc
)
Attribut (
Att_Id
Type
Desc
)
ItemAttr (
ItemNum
Att_ID
)
ProdItem (
ProductId
ItemNum
)*
*even though the table allows for N:M there is only ever a single
ItemNum in the table. If the db could change I would drop the ProdItem
table and merge the ProductId column into the Item table. But that's
not an option at this point.
here is my domain, so far everything is mapped, accept for
FinishedGood.Subassembly
class Subassmbly
{
string Description
IList<FinishedGood> FinishedGoods
}
class FinishedGood
{
string ItemNumber
Subassmbly Subassmebly
IList<FinishedGoodAttribute> Attributes
}
class FinishedGoodAttribute
{
string Category
string Description
}
and the mappings
<class name="Subassembly" table="PRODUCT">
<id column="ProductID" type="int">
<generator class="assigned" />
</id>
<property name="Description" column="ReportName" />
<bag name="FinishedGoods" access="nosetter.camelcase" batch-
size="50" table="ProdItem" inverse="true">
<key column="ProductID" not-null="true" on-delete="cascade" />
<one-to-many class="FinishedGood" />
</bag>
</class>
<class name="FinishedGood" table="ITEMNUM">
<id name="ItemNumber" column="ItemNum">
<generator class="assigned" />
</id>
<property name="Description" column="Item_Desc" />
<set name="Attributes" access="nosetter.camelcase" table="ItemAtt"
lazy="true" batch-size="10">
<key column="ItemNum" not-null="true" />
<many-to-many class="FinishedGoodAttribute" column="Att_ID" />
</set>
??? How to map the Product ???
</class>
<class name="FinishedGoodAttribute" table="ATTRIBUT">
<id column="Att_ID" type="int">
<generator class="identity" />
</id>
<property name="Description" column="Desc" />
<property name="Category" column="Type" />
</class>
my first though was to map item to product with a many to many using a
private field something like
<bag name="products" access="field">
<many-to-many class="Subassembly" />
</bag>
public Subassmebly Subassembly
{
get { return products[0]; }
set { products[0] = value; }
}
that will probably work, but it feels like the infrastructure is
bleeding into the domain. Ideally I just want an auto-property.
public Subassmebly Subassembly {get;set;}
but i don't know what the mapping would look like, or if it's possible
as all.
Another option is introducing inheritance.
abstract class BaseFinishedGood
{
ItemNumber
Attributes
}
class FinishedGood : BaseFinishedGood
{
public Subassembly Subassembly {get;set;}
}
and map FinishedGood : BaseFinishedGood as 1:1 with a many-to-one
against the product table.
again, not the cleanest, but I like this more than the previous
approach.
what are your thoughts?
--
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.