Enumeration Mapping – Introduction

In many cases, you may have tables for value lists in your database that only hold an integer primary key and a description field. Then when you want to display this description, you’ll have to join the table every time. It is not a problem for dynamic value lists or if they change on a regular basis without the need for new code implementation. But if they are static, the join looks more like a waste of time. One of the most common example is the order state in sales applications. There are only a few values like New, In Progress, Delivered and each value requires some specific code implementation. You could of course decide to load those static data when your application starts and cache them. But Entity Framework has another solution to that issue: enumeration mapping. This allows you to convert any integer field of your model to an enumeration type. This feature has some interesting advantages:

  • You no longer have to join the value list tables every time you want to get the description;
  • You don’t have to implement a caching system for value lists;
  • Enumeration types are much easier to use in code than pure integer values.
Advertisements