Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WPF MVVM Data Laher Question
Message
From
25/04/2011 14:18:23
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01508313
Message ID:
01508319
Views:
44
>I'm developing a WPF app using MVVM. I have created a Models project and a Data Layer project. The Data Layer creates, populates, and returns model objects.
>
>The question is, assume a one to many relationship such as an invoice header and invoice line items. The InvoiceHeaderModel has a list property of type InvoiceDetailModel. Where's the right place to populate this?
>
>If you do it in the model, maybe with lazy loading, then you create a dependency between the Model project into the Data Layer project. The Data Layer project knows about the Model project, but not the other way around. And, if you lazy load the child properties, then you have code in the models.
>
>The only other place I can see it would be to have a method in the DL, say GetInvoiceDetails(InvoiceHeaderModel Header) that gets the details for the invoice and populates the header model's details property.
>
>What do you think?

How about an event that is raised when data is retrieved or navigated you can subscribe to in the ViewModel. Then when it is navigated/ retrieved you can call the data model to get the related Invoice Details.

I use Mere Mortals, but I subscribe to a Data Changed event and monitor if data was retrieved or navigated and respond accordingly. Also, if I have a list of Invoices and some form of navigation, then I bind the selected item to a property in the view model. When that property changes, I can retrieve the related records because the property is two bound.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform