Why doesn't this work? Dynamic filters

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 29-Aug-2007 12:33:04   

Hello

I am trying to program a way of the user creating dynamic reports.

The user will be presented with a dropdown list of columnames, which may come from multiple tables and be able to select a value along with whether it is =, >,< etc..

So far I have a dropdown list with a list of column names from one entity and a textbox where the user can enter the value that the column anem should be = to (I am starting with = only)

The intention is to generate a report from a list of "where clauses" that the user has specified.

ie description from the drop down list and value ="my order"

At the moment I am just working with on entity, the orderDetail entity, with the intention to work out some way of doing it with multiple entities, but I have stumbled at the first hurdle.

I am trying to create the IEntityField2 to add to a filter to the bucket dynamically depending on which column the user selects.

The error I am getting is:

_The multi-part identifier "dbo.OrderDetail.Description" could not be bound. _

The code I am using so far is: (the fieldName currently selected is "Description" (dataType = text) and the containingObjectName = "OrderDetailEntity")


 string[] dropValues = DropDownList1.SelectedValue.Split('.');
            string fieldName = dropValues[1];
            string containingObjectName = dropValues[0];

            IEntityField2 ent = EntityFieldFactory.Create(containingObjectName, fieldName);
            IRelationPredicateBucket bucket = new RelationPredicateBucket((EntityField2)ent == valueTextBox.Text);

            EntityCollection orderDetail = new EntityCollection(new OrderEntityFactory());
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(orderDetail, bucket, null);
            }


What am I doing wrong? Is what I am trying to do possible?

If it is, do you also have any suggestions how I would go about doing this for multiple tables and entities?

Thanks

Bex

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 29-Aug-2007 13:11:00   

I think this field "dbo.OrderDetail.Description" is not in your OrderEntity, so you should add a relation to the OrderDetailEntity in the adapter.FetchEntityCollection. That's why the error "The multi-part identifier "dbo.OrderDetail.Description" could not be bound" occures.

grtz, Danny

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 29-Aug-2007 13:16:40   

I think this field "dbo.OrderDetail.Description" is not in your OrderEntity, so you should add a relation to the OrderDetailEntity in the adapter.FetchEntityCollection. That's why the error "The multi-part identifier "dbo.OrderDetail.Description" could not be bound" occures.

The column Description is definitly in my orderdetail table, so therefore I would have thought it would be in my OrderDetailEntity?

Its these bits that seems to be causing the problems (I think?)


   IEntityField2 ent = EntityFieldFactory.Create(containingObjectName, fieldName);
            IRelationPredicateBucket bucket = new RelationPredicateBucket((EntityField2)ent == valueTextBox.Text);

I need some sort of example of what I should be doing?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Aug-2007 15:23:04   

The following:

EntityCollection orderDetail = new EntityCollection(new OrderEntityFactory());

Should have been:

EntityCollection orderDetail = new EntityCollection(new OrderDetailEntityFactory());
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 29-Aug-2007 16:08:47   

OMG..!

I had a collegue look over this as well for obvious mistakes and they didn't notice that either..!

Thank you so much!