Open jchabot1979 opened 8 years ago
I'd rather prefer to get the code in a github repo or a zip file.
The key issue is that you do not want to load the data until the property getter is called in the UI.
One key mistake is if you have business rules that use the property as input. That will trigger a fetch of the property value when the the rule engine execute rules. To some extent that can be avaided if your rule inherit from PropertyRule and you set CanRunOnServer to false. Just put a breakpoint inside the property getter to identify what code is calling the property getter.
So the key issue is to identify which code is calling the property getter of the lazy loaded object.
For my own preference I would really consider to only send the "id values" as parameter on DataPortal.XYZ calls. Say - you are tasked to create a movile version or universal app - and now all of a sudden you need a "remote" portal and you must send the entire object over the wire - rather than just the actual values.
Ex:
public static _ContactCollection FetchChildren(Customer parent)
{
return DataPortal.Fetch<Customer._ContactCollection>(parent);
}
private void DataPortal_Fetch(Customer parent)
Should rather have been:
public static _ContactCollection FetchChildren(Customer parent)
{
return DataPortal.Fetch<Customer._ContactCollection>(parent.ID);
}
private void DataPortal_Fetch(long id)
Hi. I would like to know what is the best way to lazy load a child collection that a tab item is binded to on a tab control. I'm using CSLA, WPF, MVVM Light. I have a main view "Customer" that is an Add/Edit view. The viewModel is CustomerViewModel and has an instance of a BusinessBase "Customer" object. THis customer object has a child collection "Contacts", This contact collection is a BusinessListBase object and the BusinessBase object that is implemented in the collection is "Contact". I have a tab control with on the second tab item a user control that use the CustomerViewModel like all my 6 tab item's User control. I have a datagrid on the Contacts userControl that is binded on the Contacts child collection of the Customer object. I don't want to Fetch the Contacts from the database while loading the Customer object. I want to dynamically load it on demand the first time the user will click on the tabItem. I tough Lazy loading would be the solution. I tried setting the contactCollection as RelationshipTypes Child and LazyLoad and Fetching the data in the getter, but the getter is called at the load of the CustomerView and not when I click on the Contacts tab item. Can someone help me with it? Is there something I'm not doing good? Don't look at the adresss and Notes child collection, they are not implemented well.
Here's my BusinessObject Customer. I know there's a lot of code, but if it can help to understand. Thanks a lot
using Csla; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks;
namespace PortesDecko.BusinessObjects.MF_Customer { [Serializable] public class Customer : Base.CORE.BusinessObjects.CustomBusinessBase
{
private Customer() : base() { /* Require use of factory methods */ }
}