I would normally do it in a way that I do not get the result in memory and then processes it in c#, I think that's not constructive and my database tables are too big for it to begin with.
What I do is I write a query and pass the enum flag as a SQL parameter, the SQL "[ColumnName] & @flag=@flag" is the same as in DotNet using "property.HasFlag(MyEnum.MyFlagValue)"
public async Task<ICollection<FrequentlyAskedQuestion>> ExecuteAsync(GeoLocation language, ProductGroups productGroup)
{
var p1 = new SqlParameter("p1", (int)language);
var flag = new SqlParameter("flag", (int)productGroup);
using var db= await _contextFactory.CreateDbContextAsync();
return await db.FrequentlyAskedQuestions
.FromSqlRaw("select * from [dbo].[GetFrequentlyAskedQuestions](@p1) where ProductGroup & @flag = @flag", p1,flag)
.OrderByDescending(d=>d.AnswerWasHelpfull)
.AsNoTracking()
.ToArrayAsync();
}
in the sample, I use a UDF that returns the data from the table in the user's language or in the default language. I then further filter it in the use case that requires flags to be applied.
I am not aware of the possibility for EF to generate such query for me, taking control and writing the query will do and any changes to the schema will result in the Unit Tests failing when schema changes are not propagated.