Babak irannezhad
Babak irannezhad

Reputation: 362

how to use multiple predefined values for property in ef

I have to tables created theme by Entity Framework for example: Book Table:

public class Book
{
   public int Id { get; set; }
   public string Title { get; set; }
   public int Book_Type_Id { get; set; }
}

Book_Type Table:

public Book_Type
{
   public int Id { get; set; }
   public string Title { get; set; }
}

I will store some limited values for example Novel and education and ... in Book_Type table But in this way searching string can has spelling error. I think it's cannot be correct and may be exist a way for example use a predefined list and store specific Book type value as string. what is your opinion?

Upvotes: 0

Views: 52

Answers (1)

xdtTransform
xdtTransform

Reputation: 2057

You maybe looking for an Enum. A value type data type, where you decalre all distinct possible value. In order to have those name constant and easly refered to.

Ef does support the enum. And it's pretty strait forward. Declare then Use it.
Here is a msdn article and video about MSDN: Enum Support - Code First

Upvotes: 1

Related Questions