I have a enum:
[Flags]
public enum Role
{
Basic = 0,
A = 1,
B = 2,
C = 4,
D = 8
}
I store this value to DB in int
column Role
where Role = A | B | C
(for example), so I'm using bitwise operators.
I add 2 new values to this enum: E = 16
and F = 32
.
But I need to set these values to true by default for old DB records.
One way I see how to implement this - DB migration where Role = old Role value + 16 + 32
. Is it correct?
And is there an other way to implement this?
Since your enum has values as power of twos, your suggestion seems to be working and it's safe to assume that you can use it.
Some DB providers do have bitwise operations though, e.g: