DotNetShannon wrote:
Otis,
I saw your posting at http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=332#1464 about creating a dynamic search form with LLBLGen. I have a few questions about this.
1) How did you detect the FieldValueType for the selected field?
Using a switch, with per field index enum value a set of values:
private Control CreateValueControl(SearchField field, ref FieldValueType typeOfField, ref LabResultaatFieldIndex entityFieldIndex)
{
Control toReturn = null;
LabResultaatEntity dummyEntity = new LabResultaatEntity();
switch(field)
{
// numeric textboxes
case SearchField.AantalPerKG:
toReturn = CreateNewNumericTextBox(dummyEntity.Fields[(int)LabResultaatFieldIndex.AantalPerKG]);
typeOfField = FieldValueType.Int;
entityFieldIndex = LabResultaatFieldIndex.AantalPerKG;
break;
case SearchField.BenzProcent:
toReturn = CreateNewNumericTextBox(dummyEntity.Fields[(int)LabResultaatFieldIndex.Benz]);
typeOfField = FieldValueType.Decimal;
entityFieldIndex = LabResultaatFieldIndex.Benz;
break;
case SearchField.ClostridiumWaarde:
toReturn = CreateNewNumericTextBox(dummyEntity.Fields[(int)LabResultaatFieldIndex.Clostridiumwaarde]);
typeOfField = FieldValueType.Int;
entityFieldIndex = LabResultaatFieldIndex.Clostridiumwaarde;
break;
This you can generate of course, or write by hand or create a more generic routine.
2) How did you set the EntityFieldIndex?
Where exactly?
3) Your search form is only suitable for one entity/table. If I'd like to query multiple entities/tables, what would you recommend? I thought about creating a large view, however I'd like to try avoid this approach.
These kind of searchforms are very simple: internally you have a criteria object set, which represents the query. You render these. When you render the criteria elements, you make sure that changes to these elements trigger events and handlers of these events alter the objects represented by the rendered controls.
When the query is ok, the criteria objects are transformed into predicate objects, which is pretty easy.
Filtering on one or more entities is not hard, you just have to add a way to make the user select relations. With a bit of code generation you can easily create the chunk of code which makes this possible (i.e.: for given entity E which are teh related entities?)