Is there a way to map a string column to an enum in an Entity Model?
I have done this in Hibernate, but can\'t figure it out in EMF.
An alternative is to use a static class with string const fields instead of enums.
For example:
public class PocoEntity
{
public string Status { get; set; }
}
public static class PocoEntityStatus
{
public const string Ok = "ok";
public const string Failed = "failed";
}
For added validation on the database side you can add a check constraint to verify that the column is the expected value (you can do this when mapping to an enum as well, but since the property is just a string this helps ensure the consumer of your api set the value properly).
ALTER TABLE [PocoEntity]
ADD CONSTRAINT [CHK_PocoEntity_Status]
CHECK ([Status] in ('ok', 'failed'));