An enumeration (enum) is a commonly used type, such as a parameter to represent a state, a type, and so on. But at the moment it will not be officially supported in the Ado.net Entity framework. This article describes the use of enumerations through complex types (Complex Types) in Ado.net Entity Framework 4.
This method requires the use of the Poco class, not the classes that are automatically generated by Visual Studio. Because we need to write code for complex types manually.
Database scripts:
1 if exists (select 1
2 from sysobjects
3 where id = object_id ('Account')
4 and type = 'U')
5 drop table Account
6 go
7
8 create table Account (
9 ID uniqueidentifier not null default NewSequentialID(),
10 UserName nvarchar(20) not null,
11 Password varchar(40) not null,
12 Email nvarchar(100) not null,
13 Role int not null,
14 constraint PK_ACCOUNT primary key (ID)
15 )
16
17 insert into Account (UserName ,Password,Email ,Role ) values ('Test1','Test1','test1',1)
18 insert into Account (UserName ,Password,Email ,Role ) values ('Test2','Test2','test2',1)
19 insert into Account (UserName ,Password,Email ,Role ) values ('Test3','Test3','test3',2)
This is a data table that holds the account information, and role is an enumeration type, in the database with the int type.
We write an enumeration type to represent role in the usual way
1 public enum AccountRoleEnum
2 {
3 Admin = 1,
4 User = 2
5 }