Oliver
Oliver

Reputation: 11597

Constrain nvarchar columns in entity framework codefirst?

I am writing an application that makes use of entity framework.

One of my tables is called Individuals, it needs a column Sex which should only allow the values Male, Female or Unknown.

How should this be implemented with entity framework? Of course, I can just restrict the input that the user is allowed to enter, but I'd like there to be a constraint on the database also.

Upvotes: 0

Views: 159

Answers (1)

Justin Niessner
Justin Niessner

Reputation: 245389

The column should be of type int and then mapped to a field that is an Enum that has the values Unknown, Male, Female.

Upvotes: 1

Related Questions