In this tutorial you will learn how to create lookup tables using enums in entity framework (EF) with Code-first approach.
With EF support for enums, you can include lookup tables in the code in form of enums and also have them in the database for integrity.
This tutorial provides the information you need about:
- What Is Enum In C# ?
- Creating Enum
- Creating Lookup Table Class Using Code-First Approch
- Define Foreign Key Constraint Using Code-First Conventions
- Disable Identity for Lookup Table IDs
- Seeding Enum into Lookup Table
What Is Enum In C# ?
Enum or Enumerations is used to declare a list of named integer constants. The enum is used to give a name to each constant so that the constant integer can be referred using its name.
Enumerations appear in your source code. These are things that affect program logic because you’re going to have conditional statements based on the state of some entity comparing it with some enum value. This enums represents numerical values which can get used in place of IDs in database tables.