EF Code-First - 存储 IEnumerable 的枚举

发布于 2024-12-07 02:50:34 字数 534 浏览 4 评论 0原文

我正在使用 EF June CTP,它具有简单的枚举支持。我有一个 MVC 3 视图,其中有一些复选框,提交时会作为某些枚举的数组进行检索。

public enum CheckBox : byte
{
   VALUE_1 = 1,
   VALUE_2 = 2,
   ...
}

我需要获取枚举集合 ((IEnumerable)) 并通过代码优先方法存储它。现在,该属性完全被忽略了。

我不确定它最终是否会在工作时创建一个单独的一对多表或将所有值存储在一列中,但任何想法都会很棒。只需要存储它。一旦它存储它,如果它不创建一个单独的一对多表并以某种方式将其与某些分隔字符串存储在同一个表中,那么最终会很棒,但我可能会到达这里。

谢谢。

更新1 尝试将 [Flags] 添加到枚举中但无济于事。在表生成过程中它被完全忽略。我的模型属性是:

public IEnumerable<CheckBox> Values { get; set; }

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; }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薔薇婲 2024-12-14 02:50:34

您应该使用 [Flags] 枚举而不是集合:

[Flags]
public enum Checboxes {
    SomeValue = 1,
    OtherValue = 2,
    ThirdValue = 4
}

public Checkboxes Boxes { get; set; }

Boxes = Checkboxes.SomeValue | Checkboxes.OtherValue;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文