score:2

Accepted answer

Looks like you want to create a dynamic expression and call Select on it:

private Expression<Func<BaseEntity<TKey, TUId>, long>> CreateUIdExpression<TKey,
 TUId>()
{
    var param = Expression.Parameter(typeof(BaseEntity<TKey, TUId>));
    var memberExpression = Expression.Property(param, "UId");
    var expr = Expression.Lambda<Func<BaseEntity<TKey, TUId>, long>>(memberExpression, param);

    return expr;
}

Usage:

var newQuery = query.Select(CreateUIdExpression<TKey, TUId>());

BTW, I've assumed that UId is a long.


Related Articles