How do I replace an Int property with an Enum in Entity Framework?

By : flesh

I have an entity class that has a property with an underlying db column of datatype Int, however in reality I want this property to be an Enum. Is there any way to specify that this property returns an Enum?

By : flesh


Indirectly, like so.

Personally, I leave the storage int public (for example as DbFoo, where the enum property is Foo) - that way I can still write lambdas against the column for execution at the DB, for example:

where row.DbFoo == SomeConstant

If you don't expose the storage value, you can't do this as cleanly. You could equally leave it internal, and have some methods in the context to do the filtering... here's one I wrote earlier today:

public IOrderedQueryable

This video can help you solving your question :)
By: admin