开发者

Data Mapper for Child Objects

开发者 https://www.devze.com 2023-01-10 07:26 出处:网络
Assume we have a Customer class which has a complex property called Address. Something like this: public class Customer

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 p开发者_如何学JAVAersist 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消