0

This is somewhat new territory for me.

I'm using MVC3 with SQL CompactEdition version 4.0 and EntityFramework version 4.1 (with CodeFirst), and MVC Scaffolding by Steven Sanderson (although I don't think that last point is relevant).

I've got several different model classes that have properties that are enums. I find that when CodeFirst generates the schema for those tables, there is no column corresponding to those properties.

What's the correct way to handle this situation?

1 Answer 1

3

EF does not support enums, plain and simple.

The easiest workaround is having a mapped property that converts the enum to/from a string or int (depending on how you want to store the values)

The alternative, of course, is choosing a more mature framework (NHibernate is the one I like, but there are others)

Sign up to request clarification or add additional context in comments.

2 Comments

So define the model object with two properties, one of which is a string or int with automatic getter/setter, and the other is the enum with a getter/setter doing the mapping? Or can I simply define one property that is the enum with a getter/setter mapping to an explicitly defined string or int backing store? (i.e., does EF work only with properties, or can it work with the underlying fields?)
@DaveHanna: AFAIK, EF works with properties. As long as you expose something it recognizes, you can define the backing storage any way you see fit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.