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:
1
CREATE 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
16
EXEC 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
19
Same Enum Items:
20
INSERT INTO [dbo].[BankAccountType] VALUES ('Checking', 'A Valid Checking Account')
21
INSERT 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
}