'Set datatype in C# with 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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source