代码之家  ›  专栏  ›  技术社区  ›  Charlie

llblgen pro:如何计算给定字符串的EntityField

  •  1
  • Charlie  · 技术社区  · 15 年前

    我有一个llblgen pro项目,它生成了vb.net 2.0自助服务代码。

    我有一个函数,可以根据使用生成的代码进行的搜索返回自定义结构的列表。

    我想为这个函数提供一个字段名和值的字典,并为每个字段名和值在搜索中添加一个新的谓词表达式。

    如何检查字典中表示字段名的字符串,并确定要为哪个EntityField添加预关联表达式?

    代码样本

    Dim dbFiles As New AllFilesCollection
    Dim dbFilter As New PredicateExpression
    
    If Not String.IsNullOrEmpty(ClientName) Then
      dbFilter.Add(New PredicateExpression(AllFilesFields.ClientMenuName = ClientName))
    End If
    
    If Not String.IsNullOrEmpty(SearchText) Then
      dbFilter.Add(New FieldLikePredicate(AllFilesFields.ClientReference, "%" & SearchText & "%"))
      dbFilter.AddWithOr(New FieldLikePredicate(AllFilesFields.Cmsnumber, "%" & SearchText & "%"))
    End If
    
    For Each Filter As KeyValuePair(Of String, String) In Filters
    
      'Custom code here to determine the field to add a filter for.
    
    Next
    
    dbFiles.GetMulti(dbFilter)
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   TonyOssa    15 年前

    我认为这个问题被忽略了,因为它看起来像一个llblgen问题,但可能不是。

    如果你知道你所有的专栏:

    • 西蒂
    • 状态
    • 拉链

    然后你只需要把字符串转换成这样的值…

    For Each Filter As KeyValuePair(Of String, String) In Filters
        Select Case filter.Key
            Case "City"
                dbFilter.Add(New PredicateExpression(AllFilesFields.City = filter.Value))
            Case "State"
                dbFilter.Add(New PredicateExpression(AllFilesFields.State = filter.Value))
            Case "Zip"
                dbFilter.Add(New PredicateExpression(AllFilesFields.Zip = filter.Value))
        End Select
    Next
    
        2
  •  0
  •   David Elizondo    15 年前

    你也可以这样做:

    Dim fields As IEntityFields = new AllFieldsEntityFactory().CreateFields();
    For Each Filter As KeyValuePair(Of String, String) In Filters
        dbFilter.Add((EntityField) fields[Filter.Key] == Filter.Value);
    Next