C# Linq Expressions - Use String functions for all EF4 class attributes <p> I have this EF class called COMPONENT</p> <pre class="lang-cs prettyprint-override"><code>public partial class COMPONENT : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _ID; private string _NAME; private string _BRAND; private string _IMAGE; private System.Nullable&lt;double&gt; _PRICE; private string _OBSERVATION; private int _COMPONENT_TYPE_ID; private string _USERNAME; private System.DateTime _CREATE_DATE; </code></pre> <p>I want to treat all it's attributes like strings in the predicates of a generic query function using LinqKit PredicateBuilder.<br> The function is something like this:</p> <pre class="lang-cs prettyprint-override"><code> public static List&lt;TEntity&gt; getResults&lt;TEntity&gt;(IList&lt;PredicateFilter&gt; conditions) where TEntity: class { var predicate = PredicateBuilder.True&lt;TEntity&gt;(); foreach (var condition in conditions) { var lambda = createPredicateLambda&lt;TEntity&gt;(condition); predicate = predicate.And(lambda); } DataClassesDataContext db = new DataClassesDataContext(); var components = from com in db.GetTable&lt;TEntity&gt;().Where(predicate) select com; return components.AsExpandable().ToList(); } </code></pre> <p>The class PredicateFilter look like this:</p> <pre class="lang-cs prettyprint-override"><code> public class PredicateFilter { public string attribute; public string logicOperator; public object value; } </code></pre> <p>The problem became in the function createPredicateLambda(condition). This function returns a Expression>. In it's body calls another function called createLambdaExpression</p> <pre class="lang-cs prettyprint-override"><code> createLambdaExpression&lt;TEntity&gt;(string methodOperator, ParameterExpression param, MemberExpression attribute, ConstantExpression value) where TEntity : class </code></pre> <p>This function, in certain conditions, try to generate a expression where the attribute contains the value (no matter the Type of both the parameter) I want to do something like this but i don't see the solution:</p> <pre class="lang-cs prettyprint-override"><code> return Expression.Lambda&lt;Func&lt;TEntity, bool&gt;&gt;(Expression.Contains(Expression.Convert(attribute,typeof(string)),value),param); </code></pre> <p>Obviously this wont's compile (The Expression.Convert it's not implemented). However, if i use </p> <pre class="lang-cs prettyprint-override"><code> Expression.Lambda&lt;Func&lt;TEntity, bool&gt;&gt;(Expression.Equal(Expression.Convert(attribute,typeof(string)),value),param); </code></pre> <p>i get an exception in runtime: "The binary operator Equal is not defined for the types 'System.Int32' and 'System.String'".</p> <p>Like i said later, i want to compare different data types or use (in certain conditions) the method String.Contains in all the data types. I've tried without any luck... Anyone knows if this can be done?</p> <p>Thanks in advance!</p>