I am building two C# three-tier applications that get their data a very old database Customer table that has about 100 columns. They perform some logic in the business layer and a presentation layer displays the data.
The layout of the customer table is –
CustomerID
Firstname
Lastname
DateOfBirth
Othervalue1
Othervalue2
Othervalue3
.
.
Othervalue95
Creationdate
Updatedate
For these two applications I only need the customer table, but I am building the a new data access layer with Entity Framework. Future projects will need access to other tables and will add to this access layer.
I will use the Unit of work and repository patters.
My problem is the following –
Application A needs one subset of the customer table columns
and
Application B needs a different subset of the customer table columns (there is some overlap with Application A’s needs)
How do I perform mapping from the data layer to these two independent business layers? I know I can use automapper to perform mapping from an data entity class to a business layer class, but I will have two different business layer Customer classes.
I have been reading a bit about DTO’s but I don’t see where there should go in this n-tiered application.
You can use any of these based on your application design
1 – Map customer table to two or more Entities
2 – Have a base entity like CustomerBase and 2 or more sub entities.
3 – DTOs are Data Transfer Objects and they are (normally) mutable. Changing them wont result a CRUD operation on the DB.
DTOs are used in scenarios like: Customer entity is a heavyweight object(say 100 columns) and you just need a subset of that data (say 20 columns).
Conversion between the DTO object and the actual Entity could be implemented in many ways like auto-mapper, manually operator oveloading and more …
Hope this helps