Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although I did recieved some prompt answers, and I thank you all for that. The method shown on the replies I've got didn't work.</p> <p>I had to keep searching until I eventually found a way to do what I needed in a post from Frederic Ouellet at <a href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0" rel="nofollow noreferrer">Microsoft Forums</a>.</p> <p>In short it's the extension method below:</p> <pre><code> public static IQueryable&lt;T&gt; WhereIn&lt;T, TValue&gt;(this IQueryable&lt;T&gt; source, Expression&lt;Func&lt;T, TValue&gt;&gt; propertySelector, params TValue[] values) { return source.Where(GetWhereInExpression(propertySelector, values)); } public static IQueryable&lt;T&gt; WhereIn&lt;T, TValue&gt;(this IQueryable&lt;T&gt; source, Expression&lt;Func&lt;T, TValue&gt;&gt; propertySelector, IEnumerable&lt;TValue&gt; values) { return source.Where(GetWhereInExpression(propertySelector, values)); } private static Expression&lt;Func&lt;T, bool&gt;&gt; GetWhereInExpression&lt;T, TValue&gt;(Expression&lt;Func&lt;T, TValue&gt;&gt; propertySelector, IEnumerable&lt;TValue&gt; values) { ParameterExpression p = propertySelector.Parameters.Single(); if (!values.Any()) return e =&gt; false; var equals = values.Select(value =&gt; (Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue)))); var body = equals.Aggregate&lt;Expression&gt;((accumulate, equal) =&gt; Expression.Or(accumulate, equal)); return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(body, p); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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