Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/" rel="nofollow noreferrer">To work around this restriction, you can manually construct an expression (Source)</a></p> <p><strong>C#</strong></p> <pre><code>static Expression&lt;Func&lt;TElement, bool&gt;&gt; BuildContainsExpression&lt;TElement, TValue&gt;( Expression&lt;Func&lt;TElement, TValue&gt;&gt; valueSelector, IEnumerable&lt;TValue&gt; values) { if (null == valueSelector) { throw new ArgumentNullException("valueSelector"); } if (null == values) { throw new ArgumentNullException("values"); } ParameterExpression p = valueSelector.Parameters.Single(); // p =&gt; valueSelector(p) == values[0] || valueSelector(p) == ... if (!values.Any()) { return e =&gt; false; } var equals = values.Select(value =&gt; (Expression)Expression.Equal(valueSelector.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;TElement, bool&gt;&gt;(body, p); } </code></pre> <p>Using this utility method,</p> <pre><code>var query2 = context.Entities.Where(BuildContainsExpression&lt;Entity, int&gt;(e =&gt; e.ID, ids)); </code></pre> <p><strong>VB.Net</strong></p> <pre><code>Public Shared Function BuildContainsExpression(Of TElement, TValue)( _ ByVal valueSelector As Expression(Of Func(Of TElement, TValue)), _ ByVal values As IEnumerable(Of TValue) _ ) As Expression(Of Func(Of TElement, Boolean)) ' validate arguments If IsNothing(valueSelector) Then Throw New ArgumentNullException("valueSelector") If IsNothing(values) Then Throw New ArgumentNullException("values") Dim p As ParameterExpression = valueSelector.Parameters.Single() If Not values.Any Then Return _ Function(e) False End If Dim equals = values.Select( _ Function(v) _ Expression.Equal(valueSelector.Body, Expression.Constant(v, GetType(TValue))) _ ) Dim body = equals.Aggregate( _ Function(accumulate, equal) _ Expression.Or(accumulate, equal) _ ) Return Expression.Lambda(Of Func(Of TElement, Boolean))(body, p) End Function </code></pre> <p>Using this utility method</p> <pre><code> Dim query = m_data. Offer If (selectedSectors.Count &gt; 0) Then query = query.Where(BuildContainsExpression(Function(o As Offer) o.Value, selectedSectors)) End If </code></pre>
    singulars
    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