0

2 つの CheckboxLists があります。チェックされた項目に基づいて、チェックされた値がコンマ区切りの文字列に連結され、エンティティ フレームワーク メソッドに渡されます。結果は List(Of Entity) になります。

変換したい

SELECT * 
FROM dbo.Findings /*Below criteria is added only if any of the values are checked*/
WHERE FindingCategoryId IN (<Checked Values>) 
  AND FindingSeverityId IN (<CheckBoxValues>)

EF の VB.Net の IN に相当するものを見つけることができません。

ここでC#の投稿を見て、以下のコードを思いつきました。次のようなエラーが表示されます

タイプ 'System.Object' の定数値を作成できません。このコンテキストでは、プリミティブ型 (Int32、String、および Guid など) のみがサポートされます。

INVb.Net で句を使用するにはどうすればよいですか? どんな助けでも大歓迎です。

私のコード:

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 > 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 > 0) Then
                result = result.Where(Function(i) fcArray.Contains(i.FindingCategoryId))
            End If
        End If
        Return result.ToList()
    End Using
End Function
4

1 に答える 1

1

fsArray と fcArray を List(Of Integer) に変更したところ、うまくいきました。コードは次のとおりです。

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, _
                                .AuditTypeLoanId = f.AuditTypeLoanId, _
                                .FindingCategoryId = f.FindingCategoryId, _
                                .CategoryDescription = f.FindingCategory.CategoryDescription, _
                                .FindingSeverityId = f.FindingSeverityId, _
                                .SeverityDescription = f.FindingSeverity.SeverityDescription, _
                                .TargetId = f.TargetId, _
                                .UserResponse = f.UserResponse, _
                                .Field = If(f.FindingTargetId = findingTargetId, hmd.ColumnDescription, cl.CheckListDesc), _
                                .OldValue = f.OldValue, _
                                .NewValue = f.NewValue, _
                                .Comments = f.Comments, _
                                .EnteredBy = f.ADUser.DisplayName, _
                                .EnteredDate = f.EnteredDate _
                            })


            If (Not String.IsNullOrEmpty(findingSeverity)) Then
                Dim fsList As New List(Of Integer)
                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
                        fsList.Add(j)
                    End If
                Next
                If (fsList.Count > 0) Then
                    result = result.Where(Function(i) fsList.Contains(i.FindingSeverityId))
                End If
            End If
            If (Not String.IsNullOrEmpty(findingCategory)) Then
                Dim fc = findingCategory.Split(",")
                Dim fcList As New List(Of Integer)
                For i As Integer = 0 To fc.Count - 1
                    Dim j As Integer = 0
                    If (Integer.TryParse(fc(i), j)) Then
                        fcList.Add(j)
                    End If
                Next
                If (fcList.Count > 0) Then
                    result = result.Where(Function(i) fcList.Contains(i.FindingCategoryId))
                End If
            End If
            Return result.ToList()
        End Using
    End Function
于 2013-07-17T21:31:46.630 に答える