I have a tiered app written in C# -
Front end - (Get pages of
Customers
)Business - (
CustomerService
andCustomer
class)DataContracts - (
CustomerDTO
)DataAccess - (
UnitOfWork
andRepositories
)
The database has a Customer table with over a hundred columns (many redundant), so I'm using a DTO to populate a Customer object at the business layer. In the Customer class I have changed the names of many of the fields from their database names too, e.g. ID to CustomerID, FName to Firstname.
The front end uses services at the business layer to get Customers, e.g. GetAll(), GetByID(int customerID).
I also want to offer a GetPaged method
like below.
CustomerService class
public IEnumerable<Customer> GetPaged(
Func<IQueryable<Customer>, IOrderedQueryable<Customer>> orderBy,
int skip,
int take)
{
foreach (var customerDTO in
unitOfWork.CustomerRepository.GetPaged(orderBy, skip, take))
{
yield return new Customer(customerDTO);
}
}
But this will not work because the CustomerRepository
is expecting an orderBy
based on the CustomerDTO
not the Customer
.
I don't want the front end to know anything about the CustomerDTO
.
How can I achieve this?