LLBLGen Pro:如何评估给定String的EntityField

时间:2009-08-24 09:55:21

标签: vb.net llblgenpro

我有一个LLBLGen Pro项目,它已经生成了VB.Net 2.0 Self Servicing代码。

我有一个函数可以使用生成的代码基于搜索返回自定义结构列表。

我想为此函数提供FieldNames和Values字典,并为每个函数添加一个新的谓词表达式。

如何检查字典中表示字段名称的字符串,并确定要为其添加Predciate表达式的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 个答案:

答案 0 :(得分:1)

我认为这个问题被忽略了,因为它看起来像一个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

答案 1 :(得分:0)

您也可以这样做:

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