I use Entity Framework Code First
approach in my MVC
application and I have some entity classes for every table in the database. On the other hand, I need to use some lookup values i.e. gender, status for which I do not want to create a separate domain model or table and for this reason I need to define enum
values in a related domain model class or a separate class. Although there are many samples on the web, I have not found a suitable one for EF
and MVC
. Could you please give a sample usage that performs this requirements?
Note : I use MVC5
and EF6
.
Here is my entity class called Visitor
and sample entity that can be defined in a separate class (.cs file) or in the same class (.cs file):
namespace MyProject.Entities
{
public class Visitor
{
[Key]
public int VisitorID { get; set; }
public string VisitorName { get; set; }
//[ForeignKey("ReasonOfVisit")]
public byte ReasonOfVisit { get; set; }
//code omitted for brevity
}
public enum ReasonOfVisit
{
NotSet = 0,
Business meeting = 1,
Periodic visit = 2,
Getting information = 3,
Leaving package = 4
}
}
public ReasonOfVisit ReasonOfVisit { get; set; }
– Indifference