CodeSmith Community
Your Code. Your Way. Faster!

Table Data Enum


posted by Robert Hinojosa
04-19-2007

Downloads: 441
File size: 4.7kB
Views: 1,438
Table Data Enum

The TableDataEnum template will create an enumeration based on Type Tables in your database.  It was adapted from a feature in the .netTiers templates.
The template takes a Type Table that can have up to 3 columns.  It must have a numeric type primary key column, a string type name column, and an optional string type description column. If the table meets that criteria, when executed, an enumeration for the table data will be created.

 Example:

1CREATE TABLE [dbo].[BankAccountType](
2 [bankAccountTypeId] [int] IDENTITY(1,1) NOT NULL,
3 [bankAccountTypeName] [varchar](50) NOT NULL,
4 [bankAccountTypeDescription] [varchar](250)NULL,
5 CONSTRAINT [BankAccountType_PK] PRIMARY KEY CLUSTERED
6(
7 [bankAccountTypeId] ASC
8)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
9 CONSTRAINT [BankAccountType_UC1] UNIQUE NONCLUSTERED
10(
11 [bankAccountTypeName] ASC
12)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
13) ON [PRIMARY]
14
15-- Add Table Description
16EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'All allowable Checking Account types for my ABC System' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'BankAccountType'
17
18
19Same Enum Items:
20INSERT INTO [dbo].[BankAccountType] VALUES ('Checking', 'A Valid Checking Account')
21INSERT INTO [dbo].[BankAccountType] VALUES ('Savings', 'A Valid Savings Account')


Generated Enumeration:

1 /// <summary>
2 /// All allowable Checking Account types for my ABC System
3 /// </summary>
4 /// <remark>Enum that contains the items in BankAccountType</remark>

5 [Serializable]
6 public enum BankAccountTypeList
7 {
8
9 /// <summary>
10 /// A Valid Checking Account
11 /// </summary>

12 [EnumTextValue("A Valid Checking Account")]
13 Checking = 1,
14
15
16
17 /// <summary>
18 /// A Valid Savings Account
19 /// </summary>

20 [EnumTextValue("A Valid Savings Account")]
21 Savings = 2
22 }


 


Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems