EF Code-First - Storing IEnumerable Of Enum
I'm using EF June CTP which has simple enum support. I have a MVC 3 view which has checkboxes that when submitted are retrieved as an array of some enum.
public enum CheckBox : byte
{
VALUE_1 = 1,
VALUE_2 = 2,
...
}
I need to take that colelction of enums ((IEnumerable)) and store that via code-first approach. Right now, that property is being ignored altogether.
I'm not sure if it would ultimately, when works, would create a separate one-to-many table or store all the values in one column but any ideas would be great. Just need to store it. Once it stores it, it would be ultimately be awesome if it didn't create a separate one-to-many table and somehow store it within the same table as some delimited string but I'm reaching here probably.
Thank you.
UPDATE 1 Tried adding [Flags] to the enum to no avail. 开发者_高级运维It gets completely ignored during table generation. My Model property is:
public IEnumerable<CheckBox> Values { get; set; }
You should use a [Flags]
enum instead of a collection:
[Flags]
public enum Checboxes {
SomeValue = 1,
OtherValue = 2,
ThirdValue = 4
}
public Checkboxes Boxes { get; set; }
Boxes = Checkboxes.SomeValue | Checkboxes.OtherValue;
精彩评论