以下のような既存のコントローラーアクションがあります。
Public Function List(ByVal UserID As Integer, Optional ByVa; Filter As String = Nothing) As ActionResult
Dim records
If Filter IsNot Nothing Then
records = context.Contacts.Where(Function(x) x.UserID = UserID and x.Name.Contains(Filter))
Else
records = context.Contacts.Where(Function(x) x.UserID = UserID)
End If
return View(records)
End Function
以下のように簡単にしたいと思います。
Public Function List(ByVal UserID As Integer, Optional ByVa; Filter As String = Nothing) As ActionResult
Dim records = context.Contacts.Where(Function(x) x.UserID = UserID)
If Filter IsNot Nothing Then
records = records.Where(Function(x) x.Name.Contains(Filter))
End If
return View(records)
End Function
Filter が渡された場合、EF は 2 つのクエリを起動しますか?それとも 1 つのクエリだけを起動するのに十分なほどインテリジェントですか?