I have a list of objects. Each object contains a list of the categories to which it belongs. (Each object can exist in more than one category.) Each child Category object has a Name property that indicates the name of that category.
In my application, I present the user with this list of objects bound to a simple list control. This is accomplished using a "default" view with pre-defined sorting and no filtering. Via a drop-down list, the user can select which category they would like to filter the list by. Ordinarily, if there was a one-to-many relationship between the category and my objects, this would be simple and I'd just create a new ObjectListView filtered on "Category = 'x'". However, because there is no one Category property or value, this won't work.
I tried using "Child.Name = 'x'" as my filter expression but that threw an exception from ADO.NET saying that it didn't recognize Child. I also tried having my Category collection return a string containing a comma-delimited list of the names so I could use "'x' IN Categories" where Categories is the property name on my object - but it didn't like that either.
So, how do I accomplish this? Essentially I need a way to filter the list based on whether the object contains a child Category object with the specified name - or the name is in a list exposed by the object. Can this be done with the ObjectListView?
Any suggestions?
Thx
SonOfPirate,
What about adding another "Get" method to your list object? So where you now have ObjectList.Get(), you would also create an ObjectList.GetByCategory() (or more than one if you have different parameter signatures). The Data_Portal_Fetch for that particular method would call its own specific stored procedure for the objects to be returned. All the real work is done in the stored procedure (where you would return the object if ANY category associated with it matched...). The idea is that you are not really "filtering" a returned recordset, but rather controlling what is being returned in the recordset in the first place (yes, you will need to be able to address parameters being passed in the fetch). So:
if (condition) // You need to get list by Category
{
DisplayList(ObjectList.GetByCategory());
}
else
{
DisplayList(ObjectList.Get());
}
private void DisplayList(ObjectList list)
{
Csla.SortedBindingList<ObjectInfo> sortedList = new Csla.SortedBindingList<ObjectInfo>(list);
sortedList.ApplySort("Name", ListSortDirection.Ascending);
this.ObjectListBindingSource.DataSource = sortedList;
}
Just a thought,
Ken K
Yea, I guess I should have included in my original post that the app is "document-centric" in nature meaning that we have to operate as if all of our objects exist ONLY in memory. Therefore, instantiating different lists using SQL to do the filtering is not an option.
Essentially, the user creates a new "document" and begins adding items. Until they explicitly save the "document", nothing is persisted in the database. As a result, all of the filtering required to support multiple views in the UI must be done directly on the business collections.
Besides that, making round-trips everytime they want to VIEW that data differently is undesirable and highly unproductive (imo). In addition, we'd be consuming more and more memory as we'd actually have multiple instances of the same object in memory - another key to why we are using the ObjectListView approach.
Again, the issue is that we want to filter our list based on whether an item contains a particular value or object in its child collection. It's the many-to-many relationship that exists between our objects and each "Category" that makes this different from the standard pattern.
Thx.
Copyright (c) Marimer LLC