views:

346

answers:

2

I have an LLBLGen Pro project which has generated VB.Net 2.0 Self Servicing code.

I have a function to return a list of custom structures based on a search using the generated code.

I would like to supply a Dictionary of FieldNames and Values to this function and for each one add a new Predicate Expression to the search.

How can I check the String within the dictionary that represents the Field name and work out which EntityField to add the Predciate Expression for?

Code Sample

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)
+1  A: 

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
TonyOssa
A: 

You also could do something like this:

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
David Elizondo