473,761 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enumeration practicality

Assume you have an enumeration like PhoneType { Home, Business, Cell }.
This enumeration corresponds with a lookup/dictionary table in your database
like:

phone_cd | phone_descr
1 Home
2 Business
3 Cell

Now, I could associated each enumeration value with the phone_cd used in the
database. However, that strikes me as problematic ... it's like having two
copies of the same information in different places. However, otherwise I
need to be able translate between my enumeration values, and the database
values.

Is there a best practice(s) for dealing with this situation? Obviously it
depends on the circumstances, but general comments would be appreciated.
Thanks in advance.

Mark
Nov 16 '05 #1
2 1813
Mark,

I can't see why you would need it in more than one place. If you had a
number of details that you wanted to store for each id, then I would
recommend storing it in the database (with a column for each property you
want to store).

Either that, or I would use an enumeration in code, and attach
attributes to the enumeration which have the values that you want to store.
You can get the values from these attributes through reflection.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark" <Ma**@nowhere.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Assume you have an enumeration like PhoneType { Home, Business, Cell }.
This enumeration corresponds with a lookup/dictionary table in your
database
like:

phone_cd | phone_descr
1 Home
2 Business
3 Cell

Now, I could associated each enumeration value with the phone_cd used in
the
database. However, that strikes me as problematic ... it's like having
two
copies of the same information in different places. However, otherwise
I
need to be able translate between my enumeration values, and the database
values.

Is there a best practice(s) for dealing with this situation? Obviously it
depends on the circumstances, but general comments would be appreciated.
Thanks in advance.

Mark

Nov 16 '05 #2
Thanks Nicholas,

Are you suggesting that if I have a critical/obvious need to store the
code/description in the database, that I should likely only use the codes
(1, 2, 3) in the application rather than creating a corresponding
enumeration in my .NET code?

Thanks again.

Mark
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:OL******** ******@TK2MSFTN GP15.phx.gbl...
Mark,

I can't see why you would need it in more than one place. If you had a number of details that you wanted to store for each id, then I would
recommend storing it in the database (with a column for each property you
want to store).

Either that, or I would use an enumeration in code, and attach
attributes to the enumeration which have the values that you want to store. You can get the values from these attributes through reflection.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark" <Ma**@nowhere.c om> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Assume you have an enumeration like PhoneType { Home, Business, Cell }.
This enumeration corresponds with a lookup/dictionary table in your
database
like:

phone_cd | phone_descr
1 Home
2 Business
3 Cell

Now, I could associated each enumeration value with the phone_cd used in
the
database. However, that strikes me as problematic ... it's like having
two
copies of the same information in different places. However, otherwise I
need to be able translate between my enumeration values, and the database values.

Is there a best practice(s) for dealing with this situation? Obviously it depends on the circumstances, but general comments would be appreciated.
Thanks in advance.

Mark


Nov 16 '05 #3

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

Similar topics

1
12633
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
8
6512
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
4
5660
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation" for a second if you don't mind). However, it existed within intuitive language semantics, whereas the new "yield" keyword, while highly convenient, is also one of the most gross warping of language concepts to date... public IEnumerator...
1
5034
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/> <xsd:enumeration value="CDAUDIO"/> <xsd:enumeration value="DVD"/> <xsd:enumeration value=""/><!-- can be an empty string --> </xsd:restriction>
27
2677
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to provide a "one obvious way" to do enumerations in Python. > >>> from enum import Enum > >>> day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
3
2548
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
0
500
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
3
2711
by: eXt | last post by:
For a realtime-application (half an application at least, kind of a framework) I am working with I need a event managing system and naturally it must be fast. I have defined a set of available event types in an enumeration like this: enum Events { EVENT_FOO, EVENT_BAR, EVENT_BAZ, EVENT_CUSTOM1,
3
4795
by: muler | last post by:
hi all, After reading this excerpt from "The C# Programming Language", (By Anders) I tried to check it out. Unfortunately, I'm getting compile errors. Can anyone illustrate this with an example: ---------------------------------------------------- Section 7.7.4 - enumeration addition
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.