I'm using 3.8.2 version in my web app.
I want to implement filtering on ReadOnlyList object using LinqBindingList.I have CslaDataSource object that is bound to ReadOnlyList object that I want to filter.
protected void CslaDataSource1_SelectObject(object sender, Csla.Web.SelectObjectArgs e)
{
e.BusinessObject = GetAllChildObjects();
}
private MyReadOnlyList GetAllChildObjects()
{
object businessObject = Session["currentObject"];
if(businessObject==null || !(businessObject is MyApp.Library.MyReadOnlyList))
{
businessObject = MyReadOnlyList.GetMyReadOnlyList();
Session["currentObject"] = businessObject;
}
return (MyReadOnlyList) businessObject;
}
Now, I can implement filter using FilteredBinding list but I was looking for more flexible and "cleaner" solution. Could this be implemented using LinqBindingList like this?
private MyReadOnlyList GetFilteredChildObjects()
{
object businessObject = Session["currentObject"];
if(businessObject==null || !(businessObject is MyApp.Library.MyReadOnlyList))
{
LinqBindingList<MyChild> filter = (from x in MyReadOnlyList.GetMyReadOnlyList()
where x.MyProperty == someValue
select x) as LinqBindingList<MyChild>;
businessObject = filter;
Session["currentObject"] = businessObject;
}
return (MyReadOnlyList) businessObject;
}
and after that just to bind CslaDataSource like e.BusinessObject = GetFilteredChildObjects();
I've tried this but I got 'NullReferenceException: Object reference not set to an instance of an object.'
What am I doing wrong?
It is impossible to say without knowing exactly where that exception originates. The stack trace is required.
Copyright (c) Marimer LLC