Question about dynamic search form with LLBLGen

Posts   
 
    
Posts: 28
Joined: 17-Oct-2004
# Posted on: 21-Dec-2004 07:41:20   

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? 2) How did you set the EntityFieldIndex? 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.

Thanks in advance,

Shannon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 21-Dec-2004 10:06:28   

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

Frans Bouma | Lead developer LLBLGen Pro
Posts: 28
Joined: 17-Oct-2004
# Posted on: 21-Dec-2004 16:43:39   

Otis,

Would you make one view with all the tables that you want to query or would you keep each table seperate? I wanted to take more of a dynamic approach, so if I add any fields to some of my tables I wont have to worry about updating the code. Joining all the tables in one view isn't the best approach, however I'm having troubles coming up with another approach that would allow me to capture all the data.

For example, lets say I have a car entity. The car entity has a motor entity attached to it that just lists the basic specs of the car's motor. However, the motor entity also has a transmission entity attached to it that lists detailed specifications about the transmission. I realize this isn't the best example, but my main goal is to end up allowing a user to query fields in any of these entities and return the cars that hold those attributes. I'll end up using these cars for various types of reports (i.e. possibly with Crystal). Its pretty easy if you join all the tables together, but this isn't a good approach. Any ideas?

Thanks,

Shannon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 22-Dec-2004 10:11:22   

Don't join all the tables, that will bring your system to a halt. Start with what you want and because initially you don't have a filter, you get all of the entities of that type. So you have to filter the complete set to get the subset you (or the user) needs. So you need a way to construct the filter to create (define) that subset.

This sounds very generic, but it's the idea behind the filtering system. I think with that basic idea in mind, setting up the way the user constructs the actual filter is pretty straight forward.

Frans Bouma | Lead developer LLBLGen Pro