Note that there are some explanatory texts on larger screens.

plurals
  1. POERROR Static method requires null instance, non-static method requires non-null instance
    text
    copied!<p>I am trying to create an expression tree. I need to read data from a data table and check its columns. The columns to be checked and also the number of columns to be checked are known at run time only. The column names are given to me as a string array and and each column has a List of strings to be checked. I tried out sample expression trees , like the one below.</p> <p>Here I am encountering an error.</p> <p><strong>Static method requires null instance, non-static method requires non-null instance. Parameter name: instance</strong></p> <p>at the line </p> <p><strong>inner = Expression.Call(rowexp,mi, colexp);</strong></p> <p>Kindly help me out!!!</p> <pre><code>IQueryable&lt;DataRow&gt; queryableData = CapacityTable .AsEnumerable() .AsQueryable() .Where(row2 =&gt; values.Contains(row2.Field&lt;string&gt;("Head1").ToString()) &amp;&amp; values.Contains(row2.Field&lt;string&gt;("Head2").ToString())); MethodInfo mi = typeof(DataRowExtensions).GetMethod( "Field", new Type[] { typeof(DataRow),typeof(string) }); mi = mi.MakeGenericMethod(typeof(string)); ParameterExpression rowexp = Expression.Parameter(typeof(DataRow), "row"); ParameterExpression valuesexp = Expression.Parameter(typeof(List&lt;string&gt;), "values"); ParameterExpression fexp = Expression.Parameter(typeof(List&lt;string&gt;), "types"); Expression inner, outer, predicateBody = null; foreach (var col in types) { // DataRow row = CapacityTable.Rows[1]; ParameterExpression colexp = Expression.Parameter(typeof(string), "col"); // Expression left = Expression.Call(pe, typeof(string).GetMethod("ToLower", System.Type.EmptyTypes)); inner = Expression.Call(rowexp,mi, colexp); outer = Expression.Call(valuesexp, typeof(List&lt;string&gt;).GetMethod("Contains"), inner); predicateBody = Expression.And(predicateBody,outer); } MethodCallExpression whereCallExpression = Expression.Call( typeof(Queryable), "Where", new Type[] { queryableData.ElementType }, queryableData.Expression, Expression.Lambda&lt;Func&lt;DataRow,bool&gt;&gt;(predicateBody, new ParameterExpression[] { rowexp })); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload