I have an entity Customer
. Customer has a collection of Accounts
. I have corresponding classes. The Customer class has-a List<Accounts>
.
I have two views. First page shows the Customer's name, address etc. Each field is data-bound to corresponding property on the Customer object. There is a link show-accounts. On clicking that link, you get a second view. There is a grid which is data-bound to the Accounts
property on the customer object.
Now I need to provide a No-of-accounts
label on the first view. Problem is there is no such property on the Customer
business object. I have a few approaches to do so, but I do not like either of them.
Add a property
AccountCount
onCustomer
object. But it is artificial. What if tomorrow I need to show theBalance
in the highest account?Use the
Count
property on theAccounts
list. But this needs the list to be populated. My users rarely view the whole list of accounts. I do not see the point of loading the entire accounts table just to show the count.Once databinding is complete, make a seperate call from UI directly to Data-Layer. Let a query fetch just the details. This defeats the whole layered/tired architecture. Soon everything falls into chaos, with everyone maintaining this code firing their own queries.
Rather that Data Binding to the business model
Customer
, I can Data bind to aCustomerViewModel
class. This class can have the artificialCountOfAccounts
property. This keeps UI specific code separate from BL. Problem is ViewModel class depends on the BO layer, but the BO does not have that property. We can populate theAccounts
list and fetch the count from there, but fetching a table for just getting theCount
seems overkill.
Question
What can I do when my UI wants things different from the Business Model?