我正在设计一个应用程序的对象模型,并且对象和表格之间存在一定程度的阻抗失配。例如我有:
Product
-----------
ProductId,
ProductTypeCode,
StatusCode,
SKUNumber
ProductMarketAvailability
--------------------------
ProductMarketAvailabilityId,
ProductId,
MarketId,
Rank
ProductDescription
------------------
ProductDescriptionId,
ProductId,
MarketId,
StatusId,
DescriptionTypeId,
Description
(我没有说明查找表:状态、描述类型、产品类型、市场)
我想要一个DOMAIN CLASS:
Product
--------------
ProductId,
SkuNumber,
MarketId,
MarketName,
StatusCode,
Status,
Title ,
Description,
Caption,
Rank
使用 LLblGen pro 或实体框架:
- how i can map these tables my domain class?
- Is it a best way to deal with this through Domain classes or better to
isolate domain classes from ORM generated classes
- If I manually map ORM classes data to my domain classes then when i
persisting my Domain classes (imagine they are POCO Self tracking),
how can i write managable , well crafted code ?
i dont want to write , it doesnt look so right to me:
if (myProduct.TitleisDirty)
{
ProductDescription p= myRepository.GetDescriptionById
(myProduct.ProductDescriptionIdForTitle);
p.Description=myProduct.Title;
p.SubmitChanges();
}
if (myProduct.RankisDirty)
{
ProductMarketAvailability pma= myRepository.GetMarketById
(myProduct.ProductMarketAvailabilityId);
pma.Rank=myProduct.Rank;
pma.SubmitChanges();
}
非常感谢您的阅读。