Using Expression to create lambda


In this Blog we are going to see how we can use Expressions to create lambda .

To create Lambda using Expression use the following code :

  Type entType=  entity.GetType();
            string property = "Name";
            ParameterExpression cs;
            int id = 101;
            var lambda1 = Expression.Lambda(
             Expression.Equal(
                     Expression.Property(
                             cs = Expression.Parameter(entType, "p"),
                             entType.GetProperty(property).GetGetMethod()
                     ),
                     Expression.Constant("")
             ), new ParameterExpression[] { cs }
);