given this function:
Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _
ByVal FirstName As String, _
ByVal DateOfService As String, _
ByVal CPTCode As String, _
ByVal Contract As String, _
ByVal ClaimNumber As String, _
ByVal PaidAmount As String, _
ByVal CheckNumber As String, _
ByVal SortExpression As String, _
ByRef count As Integer) As RemitLineItemEntity()
I am trying to build up where clause one piece at 开发者_如何学Ca time based on parameters passed into the function, like so:
If Not String.IsNullOrEmpty(AccountNumber) Then
If AccountNumber.Contains("%") Then
remits = remits.Where(Function(r) r.MedicalRecordNumber Like AccountNumber.Replace("%", "*"))
Else
remits = remits.Where(Function(r) r.MedicalRecordNumber = AccountNumber)
End If
End If
If Not String.IsNullOrEmpty(LastName) Then
If LastName.Contains("%") Then
remits = remits.Where(Function(r) r.LastName Like LastName.Replace("%", "*"))
Else
remits = remits.Where(Function(r) r.LastName = LastName)
End If
End If
... many more if statements for other params
_log.Debug("Start Count query")
count = remits.Count()
_log.Debug("End Count query")
Calling this function with lastname = "smith", when I get to the count=remits.Count()
line, watching SQL Profiler it generates sql like this (prettied up from what nhibernate generates) :
Select count(*) from remitline
instead of what I expected:
Select count(*) from remitline where lastname = "smith"
What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1
TIA
Updated to latest version of ActiveRecord (3.0 RC) and this issue went away.
精彩评论