简体   繁体   中英

How many database tables should a data mapper know about?

I am writing data mappers for my next project. The overall goal, here, is to separate the job of speaking with the database from the business entities. Therefore, a user entity should know nothing about how it was built or where it's values came from.

My question is...is it common for data mappers to know and speak to multiple database tables, or is it better for each data mapper to know basically about a SINGLE table (or two) and speak to other data mappers when it needs data from a wider range of tables?

DataMappers (aka Repository pattern) see the whole persistence layer - all tables in all database(s). This is in case of relational databases and given all necessary permissions for database connectivity. This is the whole point of Repository layer - know everything about the repository.

Based on this premise, DataMapper can and should use as many tables as necessary to populate a domain object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM