I have extension method:
public static IQueryable<TResult> WithFieldLike<TResult>( this IQueryable<TResult> query, Func<TResult, string> field, string value) { Expression<Func<TResult, bool>> expr = trans => field(trans).Contains(value); return query.Where(expr); }
I need change parameter field to type: Expression>. Will be something like.
public static IQueryable<TResult> WithFieldLike<TResult>( this IQueryable<TResult> query, Expression<Func<TResult, string>> field, string value) { Expression<Func<TResult, bool>> expr = ??? return query.Where(expr); }
The call of this method is:
var query7 = query.WithFieldLike(trans => trans.DeviceModelNumber, 'ber_3');
How should I build the ‘expr’ in this case? Please help.
Deconstruct
fieldand create a new expression, something like this:(edited as per Maxs’s refinement in comments)