I'm building a WPF application, using MVVM, and Prism. It's worth noting that I'm the only developer working on a large project, so resources are limited. Here's what I currently have:
- Models - POCO's
- ViewModels - contain instances of POCO's, and utilizes the service layer based on user interaction.
- Views - bound to ViewModels
- Services - WCF services for persistence, data retrieval
I'm using Dapper to map query results to my models.
I'm curious as to how others, that don't use an ORM, handle data retrieval given that myriad of variations if returning the fully loaded POCO object would cause a pretty significant query execution.
E.G.
public class Customer : BindableBase
{
public string Name{ get; set; }
public ObservableCollection<Address> Addresses { get; set; }
public ObservableCollection<Contact> Contacts { get; set; }
}
public class Contact : BindableBase
{
public ObservableCollection<PhoneNumber> PhoneNumbers { get; set; }
}
When looking at search results for Customers, we may only display Name. So a query like SELECT Name FROM dbo.Customer
would suffice.
When editing a customer record, we need most of the data retrieved related to the Customer record, so there would be joins in the query to grab the addresses, contacts, and phone numbers.
... and there are umpteen other options, maybe they only need addresses, or just contacts.
The service layer will be used in other applications and technologies, and as such I'm going to have my business logic in there as a centralized location. Am I going to be stuck creating a function in the service layer to handle each scenario? E.G. GetSearchData(string searchCriteria)
... GetCustomerWithAddresses(int customerId)
... if so how would you go about structuring the project? I've read somewhere that another person has the service layer return the view model, which I'm not necessarily a fan of. I would still need the generic functions that return basic data for other technologies that consume the services.