As we know, Csla has FetchChild for Child Object.
anyone please tell me how to process Async FetchChild.
Thanks
Create an <Object>Accessor (a ReadOnlyRoot or CommandBase derivate) that implements the DataPortal call (and can run Async) and creates the chuld object on the "logical serverside" and returns it to the client.
This technique is described in the Csla4 EBook Creating Business Objects and I highly recommend buying it.
I have the book and I didn't find any sample that shows how to use FetchChild.
My problem is that I have a read-only child list that I want to load in a asynchronous lazy way. The book shows how to use a "child object creator", but doesn't show how this object creator gets a read-only child list from its data access region.(I've gotten 0 matches when searching FetchChild in the pdf).
It would be very interesting to see how it can be done. Maybe the book is uncomplete yet?
So the lazy loaded property would look something like this:
public static readonly PropertyInfo<AddressEditList> AddressesProperty =
RegisterProperty<AddressEditList>(c => c.Addresses,
RelationshipTypes.Child | RelationshipTypes.LazyLoad);
public AddressEditList Addresses
{
get
{
if (!FieldManager.FieldExists(AddressesProperty))
{
DataPortal.BeginFetch<AddressListCreator>((o, e) =>
{
if (e.Error != null)
throw e.Error;
else
Addresses = e.Object.Result;
});
return null;
}
else
{
return GetProperty(AddressesProperty);
}
}
private set
{
LoadProperty(AddressesProperty, value);
OnPropertyChanged(AddressesProperty);
}
}
and the AddressListCreator would be like this:
[Serializable]
public class AdresslistCreator : ReadOnlyBase<AdresslistCreator>
{
public static readonly PropertyInfo<AddressEditList> ResultProperty = RegisterProperty<AddressEditList>(c => c.Result);
public AddressEditList Result
{
get { return GetProperty(ResultProperty); }
set { LoadProperty(ResultProperty, value); }
}
private void DataPortal_Fetch(int criteria)
{
// get data from database into repository objects or use L2S / EF ....
Result = AddressEditList.GetAddressEditList(addressDataList);
}
}
}
and AddressEditList would be like this:
[Serializable]
public class AddressEditList : BusinessListBase<AddressEditList, AddressEdit>
{
internal static AddressEditList GetAddressEditList(
object childData)
{
return DataPortal.FetchChild<AddressEditList>(childData);
}
private void Child_Fetch(object childData)
{
RaiseListChangedEvents = false;
foreach (var child in (IList<object>)childData)
this.Add(AddressEdit.GetAddressEdit((child)));
RaiseListChangedEvents = true;
}
}
and further AddressEdit like this:
[Serializable]
public class AddressEdit : BusinessBase<AddressEdit>
{
internal static AddressEdit GetAddressEdit(object childData)
{
return DataPortal.FetchChild<AddressEdit>(childData);
}
private void Child_Fetch(object childData)
{
// TODO: load values
}
}
Why need AdresslistCreator ?
Why not use AddressEditList directly?
DataPortal.BeginFetch<AddressEditList >((o, e) =>
{
if (e.Error != null)
throw e.Error;
else
Addresses = e.Object.Result;
});
AddressEditList in this example is an EditableChildList with EditableChild and would normally NOT have static factory methods nor an implementation of DataPortal_Fetch with criteria object(s).
So the AddressListCreator is "readonly-root" object that accepts parameters, implements DataPortal_Fetch and is responsible for loading a child list.
it seems too lazy, Object.Addresses return null, how to resolve this?
Please post your code - impossible to give to good recommendations without a review of your code.
the code is as your code:
i use it like this in my ViewModel
AddressEditList addresslist=Object.AddressEditList ;
and the addresslist is null.
Do you check e.Error in the client side callback? if your object isn't there, maybe it is because of an error.
Maybe the book is uncomplete yet?
The preview you have of the Data Access ebook is about 50% complete, so there is a lot more content coming.
Copyright (c) Marimer LLC