I’ve got an Enum with Flags attribute.
[Flags]
public enum AlcoholStatus
{
NotRecorded = 1,
Drinker = 2,
NonDrinker = 4
}
I am creating a Sqlparameter as below.
new SqlParameter("@AlcoholStatus", SqlDbType.VarChar) {Value = (int) AlcoholStatus}
If AlcoholStatus has all the values (NotRecorded | Drinker | NonDrinker) it returns 7 as the value for the SqlParameter.
I am parsing this parameter for a stored procedure and I prefer if I can parse the value as “1,2,3,”. What’s the best way of doing this?
Or is there any other easy way to filter records by parsing integer value 7 to the stored procedure?
EDIT : This happens in a filter functionally where user wants to see people with any of above statuses.
It’s a quite complicated sql query. There I filter AlcoholStatus as below
WHERE AlcoholStatus IN "1,2,4,"
I wrote below method to get the comma separated enum ids in order to parse that to the database.