Using business objects to filter results

Using business objects to filter results

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


willwise posted on Monday, February 12, 2007

Hi Everyone. I need a quick sanity check. I'm still relatively new to CSLA but am learning it as it's used internally at my latest client. I think they might be misusing it and wanted to get your esteemed opinions on the matter.

Basically, when they conduct a search against their database they first use a general SQL to grab the results. They then loop through all relevant business objects and child objects to filter these results down based on the business rules encapsulated in the business objects. 

Fair enough, but it seems to me like it would be far more efficient to just use a more restrictive SQL query and create a new Read Only business object if necessary.  Then again, this might not mesh well with CSLA and I don't want to lead them astray.

Any help you can provide would be appreciated!

Will

RockfordLhotka replied on Monday, February 12, 2007

CSLA gives you the flexibility to choose either approach, depending on your specific needs.

In many (most?) cases, filtering should be done in the SQL statements, allowing the database to do the work and avoiding the return of unneeded data.

In some cases however, the filtering process may be complex enough that it is easier to code in C#/VB than in SQL. In that case you may retrieve all the data and filter it in the DataPortal_Fetch() method - only creating objects for data that matches your requirements.

Copyright (c) Marimer LLC