I want to have a variable field in both Where-Contains and Select. "field_a" is the guy I want to be variable (sometimes I want field_b or _c; they are strings). The code below properly builds the Select as Select(x => x.field_a). How do I get the second part of the Where clause to say, && targetCodes.Contains(x.field_a)? [db is a DbContext, itemsArray is an array of objects that have a string property called Code.]
using (var db = dbFactory.CreateInstance())
{
var parameter = Expression.Parameter(typeof(myTable), "x");
var field = Expression.Property(parameter, "field_a");
var selector = Expression.Lambda(field, parameter);
var targetCodes = itemsArray.Select(i => i.Code).ToArray();
var query = db.myTables
.Where(x => x.companyId == 1 && targetCodes.Contains(x.field_a))
.Select((Expression<Func<myTable, string>>)selector);
return await query.ToArrayAsync();
}