title: WHERE IN clause using VB.NET in Entity Framework
body: <p>I have two CheckboxLists. Based on the items checked, the checked values are concatenated into a comma separated string and passed to my entity framework method. The result would be a List(Of Entity).</p>
  
  <p>I want to convert </p>
  
  <pre><code>SELECT * 
  FROM dbo.Findings /*Below criteria is added only if any of the values are checked*/
  WHERE FindingCategoryId IN (&lt;Checked Values&gt;) 
    AND FindingSeverityId IN (&lt;CheckBoxValues&gt;)
  </code></pre>
  
  <p>I am unable to find an equivalent for IN for VB.Net in EF.</p>
  
  <p>I looked at the C# post <a href="https://stackoverflow.com/questions/1137921/how-to-do-an-in-query-in-entity-framework">here</a> and came up with the below code. I get an error as </p>
  
  <blockquote>
    <p>Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.</p>
  </blockquote>
  
  <p>How can I use the <code>IN</code> clause in Vb.Net? Any help is appreciated. </p>
  
  <p>My code:</p>
  
  <pre><code>Public Function Findings(ByVal findingSeverity As String, ByVal findingCategory As String) As List(Of Finding)
      Dim aTypeLoanId As Integer = If(Not IsNothing(AuditTypeLoanId), AuditTypeLoanId, -1)
      Dim findingTargetId = CInt(FindingTarget.LoanHeader)
      Using e As New LQCEntities()
          Dim result = (From f In e.FindingEntities _
                  From hmd In e.HeaderMetaDataEntities.Where(Function(h) h.MetaDataId = f.TargetId).DefaultIfEmpty() _
                  From cl In e.CheckListEntities.Where(Function(c) c.CheckListId = f.TargetId).DefaultIfEmpty() _
                  Where f.AuditTypeLoanId = aTypeLoanId _
                  Select New Finding With _
                         {
                              .FindingId = f.FindingId, _
                              .FindingCategoryId = f.FindingCategoryId, _
                              .FindingSeverityId = f.FindingSeverityId, _
                              .EnteredBy = f.ADUser.DisplayName, _
                              .EnteredDate = f.EnteredDate _
                          })
          Dim fsArray() = Nothing
          Dim fcArray() = Nothing
          If (Not String.IsNullOrEmpty(findingSeverity)) Then
              Dim fs = findingSeverity.Split(",")
              For i As Integer = 0 To fs.Count - 1
                  Dim j As Integer = 0
                  If (Integer.TryParse(fs(i), j)) Then
                      ReDim Preserve fsArray(i)
                      fsArray(i) = j
                  End If
              Next
              If (fsArray.Count &gt; 0) Then
                  result = result.Where(Function(i) fsArray.Contains(i.FindingSeverityId))
              End If
          End If
          If (Not String.IsNullOrEmpty(findingCategory)) Then
              Dim fc = findingCategory.Split(",")
              For i As Integer = 0 To fc.Count - 1
                  Dim j As Integer = 0
                  If (Integer.TryParse(fc(i), j)) Then
                      ReDim Preserve fcArray(i)
                      fcArray(i) = j
                  End If
              Next
              If (fcArray.Count &gt; 0) Then
                  result = result.Where(Function(i) fcArray.Contains(i.FindingCategoryId))
              End If
          End If
          Return result.ToList()
      End Using
  End Function
  </code></pre>