Filter on CSLA datasource

Filter on CSLA datasource

Old forum URL:

bharat0204 posted on Monday, March 08, 2010


i have a CSLA datasource with column Id , Name and status.

i want top apply filter to get records whose status ="Active".

PersonalInfoCollection obj = PersonalInfoCollection .GetPersonalInfoCollection();



now i have obj collection with all records and i want to filter.

i am trying to use<> but as i am new to CSLA so dont know how it work.

please help.

thanks in advance.



Curelom replied on Monday, March 08, 2010

You will need to create a new methos in your collection.  Something like PersonalInfoCollection.GetActivePersonalInfoCollection.  This would be similar to your current get method only it will have your filter information in it.  Use this new method in the CSLA datasource.

bharat0204 replied on Tuesday, March 09, 2010


thanks for your reply.

but to create a new method and again querying to database for active results is not a good idea and unnecessary hit database twice for same result and having filter condition.

please let me know if there is some way to do it in library or UI itself.

Curelom replied on Tuesday, March 09, 2010

That is how you have to do it with the CSLA DataSource.  If you want some more efficiencies, you can cache the results of the full list and have the new Active Method grab the cached results if they exist and return the filtered list via linq or some other filtering method.

I recommend you don't use the CslaDataSource in the first place as it is being removed from future versions of CSLA.

RockfordLhotka replied on Tuesday, March 09, 2010

It is CslaDataProvider that is being removed (in Silverlight at least). CslaDataSource is a key part of Web Forms support and is not being removed.

RockfordLhotka replied on Tuesday, March 09, 2010

The Version 2.1 Handbook has information on paging/sorting and filtering with the CslaDataSource.

You can absolutely do filtering of the data on the web server, without going back to the database. But to do so, you must cache all the data in memory on the web server. Unless your table is quite small, this is probably a very bad idea, and it will be cheaper and more effective to go back to the database.

But you need to make that determination yourself.

There are actually four places you can do sort/filter operations in a web forms app:

  1. In the select data event handler for the data source
  2. In the object's factory method
  3. In the DataPortal_Fetch() method
  4. In the database

Options 1 and 2 only work if you cache all the data in memory on the web server, which could be good or bad depending. Options 3 and 4 are always available, because they have access to the full set of data.

bharat0204 replied on Tuesday, March 09, 2010

Hi Rocky,

thank you very very much for your reply.

i am looking for something which you suggested.

here in my case there are only max 10 records so i want to do it through web application itself by putting data into session.

but the problem i am facing here i could not find out method or property which will do filter there only.

i have collection of all tasks and i want to filter only active task if user select ..








protected void btnFilter_Click(object sender, EventArgs e)






TaskInfoCollection allTask = (TaskInfoCollection)Session["currentObject"];


allTask.Select<> // something by that i can filter the records here only.


please suggest if there is some mech. by that i can do filter active records here only.

or some way around the same is supported in .Net dataset.

waiting for your reply.

thanks in advance.

RockfordLhotka replied on Tuesday, March 09, 2010

Can't you just use a LINQ where clause?

e.BusinessObject = allTask.Where(c => c.Property == filterValue);

Obviously you have some "filterValue" that you got from the user in the UI right? And you want to filter using that value against some property of your business objects - so the .Where() should do what you need.

bharat0204 replied on Tuesday, March 09, 2010

Thank you very much Rocky.

you are great and it works as i expect.

just for understanding what is c here..i didn't get this.


bharat0204 replied on Tuesday, March 09, 2010

and also i want to filter the recordset on two or three cateria so how to do that..



e.BusinessObject = obj.Where(c => c.Status ==

"active" AND c.Status == "frozen");

as i am writing this but it is giving me syntax error.

RockfordLhotka replied on Tuesday, March 09, 2010

obj.Where(c => c.Status == "active" && c.Status == "frozen");

Though that obviously won't work, because c.Status can never equal those two values at the same time...

Copyright (c) Marimer LLC