使用实体框架设置C#中的数据类型
我在C#代码中有此枚举:
enum MyOptionsEnum
{
Option1,
Option2,
Option3
};
我有一个使用此枚举的实体:
class OrderEntity
{
public int Id { get; set; }
public DateTime Date { get; set; }
...
public MyOptionsEnum Options { get; set; }
}
如果我想为每个订单选择一个选项,则此代码正常。
我要做的是允许用户检查1,2或3个选项(或0)。这就是我所说的“一组”选项。
这就是我所做的:
enum MyOptionsEnum
{
Option1 = 1,
Option2 = 2,
Option3 = 4
};
如果我想按特定顺序设置option1和option3,这就是我在代码中所做的事情:
order.Options = MyOptionsEnum.Option1 | MyOptionsEnum.Option3;
它有效,但对我来说很难。
让我们想象另一个开发人员在枚举中添加了一个新选项,而忘记在值中设置了2个倍数。它行不通...
我的问题:C# / Entity Framework中是否有“集合”数据类型?
谢谢
I have this enum in my C# code:
enum MyOptionsEnum
{
Option1,
Option2,
Option3
};
I have an entity which uses this enum:
class OrderEntity
{
public int Id { get; set; }
public DateTime Date { get; set; }
...
public MyOptionsEnum Options { get; set; }
}
This code works fine if I want to choose ONE option for each order.
What I want to do is to allow user to check 1,2 or 3 options (or 0). This is what I call a "set" of options.
Here is what I've done:
enum MyOptionsEnum
{
Option1 = 1,
Option2 = 2,
Option3 = 4
};
And here is what I've done in my code if i want to set Option1 and Option3 on a specific order:
order.Options = MyOptionsEnum.Option1 | MyOptionsEnum.Option3;
It works but it is ugly for me.
Let's imagine another developer which adds a new option in the enum and forget to set a multiple of 2 in the value. It won't work...
My question: is there a "Set" datatype in C# / Entity Framework ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论