using System.Linq.Expressions;
using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(GeneratePredicateForValue<DbModel, Guid>("Id", Guid.NewGuid()));
private static Expression<Func<T, bool>> GeneratePredicateForValue<T, TKey>(string fieldName, TKey value)
var pe = Expression.Parameter(typeof(T), "x");
var member = Expression.Property(pe, fieldName);
var expected = Expression.Constant(value);
return Expression.Lambda<Func<T, bool>>(Expression.Equal(member, expected), pe);
public Guid Id {get;set;}