Is this a viable alternative to a filtered list?

Is this a viable alternative to a filtered list?

Old forum URL: forums.lhotka.net/forums/t/2024.aspx


jspurlin posted on Saturday, December 23, 2006

In the example for Project List, you may apply a filter.  If you send a filter as criteria, the project list is fetched and then only filtered items are added to the list.

I also noticed that this list may reside in memory for a while, in cache. It appears, then, that a filtered list could be the list in cache.

Is it viable, and by that I mean "not bad practice" to retrieve full lists (if they are relatively small), keep the full list in memory (thus momentarily no more requests to the database are necessary) and do this:

 

private static CompetencyList _list;

/// <summary>

/// Returns a list of competencies.

/// </summary>

public static CompetencyList GetCompetencyList(int categoryId)

{

if (_list == null)

_list = DataPortal.Fetch<CompetencyList>

(new Criteria());

//return _list;

if (categoryId > 0)

{

CompetencyList newList = new CompetencyList();

newList.IsReadOnly = false;

for (int i = 0; i <= _list.Items.Count - 1; i++)

{

if (_list.ItemsIdea [I].CategoryId == categoryId)

newList.Add(_list.ItemsIdea [I]);

}

newList.IsReadOnly = true;

return newList;

}

else

return _list;

}

 

Brian Criswell replied on Saturday, December 23, 2006

It is generally considered fine to do this as long as it is uncommon for the list to change while a user is using the application.  Otherwise you need to implement some means of checking whether the cached list needs to be refreshed.

But why not use a FilteredBindingList or an ObjectListView to do your filtering?

Copyright (c) Marimer LLC