1

我有一个 LLBLGen Pro 项目,它生成了 VB.Net 2.0 自助服务代码。

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

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

如何检查字典中表示字段名称的字符串并确定要为其添加谓词表达式的实体字段?

代码示例

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

2 回答 2

1

I think that this question has been ignored because it looks like an LLBLGEN question, but it probably isn't.

If you know all of your Columns:

  • City
  • State
  • Zip

Then you just need to convert your string to those values like this...

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
于 2009-09-16T00:00:34.217 回答
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
于 2009-10-26T18:29:04.323 回答