ActiveRecord Linq / NHibernate Linq没有完全构建查询

时间:2011-07-14 19:02:48

标签: .net vb.net linq nhibernate castle-activerecord

给出这个功能:

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() 

我试图根据传递给函数的参数一次构建一个where子句,如下所示:

    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

......如果其他参数的陈述更多

        _log.Debug("Start Count query")
        count = remits.Count()
        _log.Debug("End Count query")

使用lastname =“smith”调用此函数,当我到达count=remits.Count()行时,观察SQL事件探查器它会生成这样的sql(从nhibernate生成的内容中解脱出来):

Select count(*) from remitline

而不是我的预期:

Select count(*) from remitline where lastname = "smith"

构建where子句我做错了什么?我正在使用Castle ActiveRecord 2.1

TIA

1 个答案:

答案 0 :(得分:0)

更新到最新版本的ActiveRecord(3.0 RC),这个问题就消失了。