I am trying my hardest to get my brain around using predicate expressions correctly and wondered if anyone could offer any insight on accomplishing the following...
Given the following Entities:
Letters
Content
City
State
Zip
Type
PostalType
Criteria
Field
Value
I want to extract all of the Letters that I need to send based on the content of my CriteriaEntityCollection.
Let's say I have two CriteriaEntities in the Collection
So if Criteria(0).Field = "State" and Criteria(0).Value="NC"
and Criteria(1).Field="Type" and Criteria(1).Value="NewCustomer",
how would I build a LettersEntityCollection that meets the following criteria (SQL Psudo):
" Where State = 'NC' AND Type = 'NewCustomer' "
I need to some way to generate the predicate values on the fly at runtime. I am assuming it will take a bunch of loops through the field indexes, but am wondering if there is a more simple solution i.e. generate some type of where clause to filter the LettersEntityCollection.
My idea is the following - just psudo - not necessarily using valid methods/properties:
For each Criteria in CriteriaCollection
for each FieldIndex in LettersFields
if LetterFields(FieldIndex).tostring = Criteria.Field.tostring then
AddPredicate(PredicateFactory.CompareValue(LetterFields(FieldIndex),equals,Criteria.Value)
end if
next
next
Any suggestions would be greatly appreciated.
Thanks,
Hal