Thanks for your input, Dmyrto.
I am already using the technique you described at the SP level (default NULL
values). The main dilemma I am encountering is how to create a class
interface that will allow a user to specify which parameters are optional.
I considered the interface solution you proposed, but ran into an issue.
Overloading working well when my GetEntity method only has two parameters of
different types, but some filtering requirements look like this:
Entity.GetEntity(Guid Filter1, Guid Filter2, Guid Filter3, Int32 Filter4,
Int32 Filter5, Int32 Filter6, etc.) // some methods require 15+ filters
In case above, because users must have the option to disable any or all
filters, it seems impractical to attempt to create an overload for every
possible combination. In fact, I think I would run into a technical
limitation because no 2 overloads can have the same number and type of
parameters. I could attempt to create a different method (name) where
necessary, but again this seems impractical.
Any thoughts?
Thanks again.
Chris
"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.com> wrote in message
news:O4*************@tk2msftngp13.phx.gbl...
Hello Chris,
What I would check for is whether it is possible to make those parameters
optional at the SP level and specify that their default values are NULL.
In this case, you can have two overloads of the GetCustomerList method.
The one with filtering parameters will create corresponding SqlParameter
objects when calling the SP, and the other without filtering will be
calling the SP without passing any parameters.
--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"ChrisB" <pl****************@thanks.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl... Hello:
I am writing an application using C# that needs to support several
queries that
limit the number of returned records through the use of filtering and was
hoping to get some opinions on the best way to set up the necessary class
interfaces.
For example, Customer.GetCustomerList() might require 2 filters such as a
"StateID" filter which is a Guid and and "IsActive" filter which is a
Boolean. So, the method signature would look something like this:
GetCustomerList(Guid StateID, Boolean IsActive). The main issue I am
encountering is how to allow the user to specify that no filtering will
be
used.
One option is: GetCustomerList(Boolean UseFilterByStateID, Guid
StateID, Boolean UseFilterByIsActive, Boolean IsActive). The related
stored
procedure could then use all 4 pieces of information to return the proper
records.
Another option would be to allow users to provide a"special" value to a
filter to indicate that it should not be used. Although this might work
for
a Guid filter (say, '{11111111-1111-1111-1111-111111111111}' = dont use
filter), there is no
way to indicate "no filter" for a boolean filter.
I am leaning toward the first option but would appreciate any
input. Is there a common technique for handing this type of requirement.
Have there been any helpful articles written on the subject?
Thanks!
Chris