473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

class interface for data access component

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

Nov 17 '05 #1
2 1635
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


Nov 17 '05 #2
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: orangepic333 | last post by:
Could someone tell me what's the difference between the two? Is it that a class is used within an OO language while a component can be exported between OO languages? Are there other...
6
by: GingerNinja | last post by:
Hi Everybody, its about my 4th day on C# and all seems to be going smoothly however I've started to get into Datagrids and in particular binding data sources to them. In the documentation it says I...
6
by: Edward Diener | last post by:
Since a C++ using declaration isn't allowed in MC++, is there a way to specify that a property, method, event, or field's access can be changed in a derived class, ie. is protected in one class and...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
11
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to...
4
by: Ellis Yu | last post by:
Hi All, I'm not so clear between component and class. After reading from help, component can also be said a class but implement icomponent interface. But what's scenario I should use component...
5
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have...
15
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
3
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have one question base on a choice of having a public interfcace access compare to public class member. IN other word let say that I have a public interface named ImyInterface with...
4
by: sunderjs | last post by:
Hi, This is from a typical telecom software implementation. I have three subsystems (x, y, z) which exchange data amongst them. The arrangement is such that x talks to y over interface xy. y...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.