Data Mapper for Child Objects

筅森魡賤 提交于 2019-12-23 04:36:23

问题


Assume we have a Customer class which has a complex property called Address. Something like this:

public class Customer
{
     public string Name { get; set; }
     public Address { get; set; }
}

I need to implement Data Mapper pattern to persist Customer objects to the database. Should I have something like CustomerDataMapper that persists the Customer AND the Address or 2 different Data Mappers: CustomerDataMapper and AddressDataMapper?

I'd like to know your thoughts on this.

Cheers,

Mosh


回答1:


If you want to map by hand, I would suggest having two mappers, with CustomerDataMapper delegating to AddressDataMapper for that property. This allows you to test the mappings separately and potentially reused the address mapper elsewhere.

An ORM like LINQ to SQL or NHibernate could take care of this for you.



来源:https://stackoverflow.com/questions/3402685/data-mapper-for-child-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!