I currently have a Filter object that matches a business object. This object has properties that are associated with various ways that I want to be able to filter / search for a list of such business objects. These filter objects currently have a method that builds the contents of the where clause, which is then passed to the SQL Server 2000 stored procedure, where it concatenates with the rest of the select query. The final line is then executed using Exec .
This works fine now, except that I am worried about a performance issue with lack of execution plan caching. In some studies, I have seen the use of the sp_executesql call; is this the best solution or is there a better deal for what i am doing?
Update: I think part of the problem with using sp_executesql is that based on the collection in my filter, I need to generate a list of OR statements. I am not sure that a "parameterized" query will be my solution.
Example
var whereClause = new StringBuilder(); if (Status.Count > 0) { whereClause.Append("("); foreach (OrderStatus item in Status) { whereClause.AppendFormat("Orders.Status = {0} OR ", (int)item); } whereClause.Remove(whereClause.Length - 4, 3); whereClause.Append(") AND "); }
source share