Enums and SQL Server 2005


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

We have a Enums class that contains all enums for the solution and some of these enum values actually make their way into the application database. In some queries it would be much better to show the 'text value' of an enum rather than it's integer value. Does anyone know if there is any way of doing such a thing in SQL Server 2005 now that CLR/managed code is supported? If there is can you point me to a reference or two.

Cheers, Peter

Reply
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Hey Peter,

Yeah, the SQL CLR projects are a really cool concept and work quite well.  We too had the need to localize enums and there is actually an attribute within the framework that allows enums to be localized...or provide a display value different than the actual character representation.

Using a Localization Key

Public Enum MyEnum As Integer
    <MicroFour.StrataFrame.Tools.EnumDisplayValue("AppleLocalizationKey", True)> _
    Apple = 0
    <MicroFour.StrataFrame.Tools.EnumDisplayValue("OrangeLocalizationKey", True)> _
    Orange = 1
End Enum

Just providing a more readable display value that isn't localized

Public Enum MyEnum As Integer
    <MicroFour.StrataFrame.Tools.EnumDisplayValue("An Apple", False)> _
    Apple = 0
    <MicroFour.StrataFrame.Tools.EnumDisplayValue("An Orange", False)> _
    Orange = 1
End Enum

If you use any of the SF lists and populate using the enum, these values will be automatically pulled when populated.  To manually pull the localized or readable value you can call this:

MicroFour.StrataFrame.Tools.Common.GetEnumDisplayValue(MyEnum.Apple)

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search