0

I would like to create class Person which will have int Id; string Name etc. but there is one thing I don't know how to solve.

I'll be calling every person and after the call I would like to set status for the result of call and I want only those: "SUCCESS", "DIDN'T WANT TO TALK", "CALL LATER", DID NOT PICK UP THE PHONE and that's all no more. Of course all objects of class Person will be in the LocalDb database.

As far as I remember it is called dictionary entity in databases.

How should I create this in C# one class, two classes? Is there any method to solve this to add only possible values?

I do not know if Entity Framework with deal with enum. Could somebody writa a minimal sample of Person and this Enum type which Entity Framework will understand?

Yoda
  • 17,363
  • 67
  • 204
  • 344

1 Answers1

1

Entity framework can handle enums, but from a readability viewpoint, it is not a great practice. It would mean anyone looking at the database or reporting from the database in the future would only see a meaningless integer.

A better way to do it would be use another entity and seed the database with the values you want.

public class Call
{
    ..... //some other properties you need
    public int StatusId {get;set;}    
    public virtual Status Status {get;set}
}

public class Status
{
    public int Id {get;set;}
    public int Name {get;set;}
}

You would then just seed the 3 options into status.

When adding or updating a call, you only need to assign the seeded ID of the status to StatusId as that is your FK. The virtual status property is your navigation property. So when you are accessing a status on a call you can just use Call.Status.Name or Call.Status.Id to access which status property you want to use.

Lotok
  • 4,517
  • 1
  • 34
  • 44
  • One could argue that purpose of database is to store data and not to display it... – Rytis I Jul 10 '14 at 11:51
  • @RytisI That could be argued. But in the realworld people do look at the database, SSRS reporting being just one reason. If you can make the data human readable without much effort, why wouldn't you? – Lotok Jul 10 '14 at 11:53