Fortunately, there is workaround for this. We can substitute the original non-enum property with a new property using an enum type in a partial class. For example, let's take a look at the ExpenseLog class that was generated by EF. There is a StatusID property of the type Byte that should be exposed as an ExpenseStatus Enum.
This can be achieved by first hiding the StatusID property from its callers by setting the Getter and Setter of the property to Private.
Next, create a partial class and declare a new property as follows:
public ExpenseStatus Status
{
get { return (ExpenseStatus)this.StatusID; }
set { this.StatusID = (byte?)value; }
}
That's it! Now we can use the Status property in place of the StatusID property.
No comments:
Post a Comment