Hi,
I am trying to keep a BusinessListBase type child for a BusinessBase class. Basically in my case I am using the Northwind database and have created a Customer Class derived from BusinessBase and it is having OrderList property holding all the Orders for a particular Customer. I am using the lazy load process as suggested by Rocky to Lazy load the child objects. But when I am trying to load the child BusinessListBase object I am getting the serialization exception saying List Of Order as an Unknown Type. Can you please guide me what I missed? Just to metion, the OrderList is working fine when I am accessing it as a separate object and not as a child of The Customer class.
Regards
Tiklu
Are you trying to do a GridView (control) to bind the list or some other ways to bind the lsit to the UI?
if your doing a grid then you should use BusinessBindingList NOT BusinessListBase
if your doing a grid then you should use BusinessBindingList NOT BusinessListBase
That depends on the UI technology though, and perhaps even specific controls.
WPF is the tricky one, since it depends very much on the specific datagrid control you are using and how that control works with collections.
Sorry I forgot to mention this in the first place..I am using Silverlight 4 with CSLA 4 and the data is getting bound to a telerik datagrid.
Also the exception that I am getting is this
Type 'Northwind.Model.OrderList' with data contract name 'ArrayOfOrder:http://schemas.datacontract.org/2004/07/Northwind.Model' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
Hi All,
Finally I have been able to fix the problem. Here is what I was trying to do.
1) I have written a Generic Lazy Load Method like this
protected F LazyLoadProperty<F>(PropertyInfo<F> prop, object criteria)
where F:IMobileObject
{
if (!FieldManager.FieldExists(prop))
{
MarkBusy();
if (this.IsNew)
{
DataPortal.BeginCreate<ChildLoader<F>>(criteria, (o, e) =>
{
if (e.Error == null)
{
LoadProperty<F>(prop, e.Object.Child);
}
else
{
throw e.Error;
}
MarkIdle();
OnPropertyChanged(prop);
});
}
else
{
DataPortal.BeginFetch<ChildLoader<F>>(criteria, (o, e) =>
{
if (e.Error == null)
{
LoadProperty<F>(prop, e.Object.Child);
}
else
{
throw e.Error;
}
MarkIdle();
OnPropertyChanged(prop);
});
}
}
return GetProperty<F>(prop);
}
2) And the Child Loader Class is like this
[Serializable]
public partial class ChildLoader<T> : BindableBase
where T:IMobileObject
{
#region Child
private T _child;
public T Child
{
get { return _child; }
private set
{
OnPropertyChanging("Child");
_child = value;
OnPropertyChanged("Child");
}
}
#endregion
#region Mobile Formatter
protected override void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
{
base.OnGetChildren(info, formatter);
if (this._child != null)
{
var fmt = formatter.SerializeObject(this._child);
info.AddChild("Phoenix.Model.Base.ChildLoader._child", fmt.ReferenceId);
}
}
protected override void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
{
if (info.Children.ContainsKey("Phoenix.Model.Base.ChildLoader._child"))
{
var data = info.Children["Phoenix.Model.Base.ChildLoader._child"];
this._child = (T)formatter.GetObject(data.ReferenceId);
}
base.OnSetChildren(info, formatter);
}
#endregion
#if !SILVERLIGHT
private void DataPortal_Fetch(object criteria)
{
this.Child = DataPortal.FetchChild<T>(criteria);
}
#endif
}
The part I was missing was with the OnGetChildren and OnSetChildren. I copied the code from ReadOnlyBase of CSLA 4.0.1 and now it is working fine.
Still just posted the code as it may just help somebody trying to do a lazyload of csla property
Copyright (c) Marimer LLC