Dynamic creation of FieldInfo

Posts   
 
    
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 28-Aug-2007 15:16:51   

I want to dynamically create a bucket object from user selection in a dropdown list. This is the approach I am taking, but I cannot figure out how to create a FieldInfo object based on a string. Can this be made to work or is there a better way?



            //get the values from the dropdown selecteditem
            string fieldName = "OrderId";
            string containingObjectName = "OrderEntity";

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            PredicateExpression filter = new PredicateExpression();
            IPredicateExpression predicateExpression = new PredicateExpression();
            
        //this line does not work
        FieldInfo fieldInfo = new FieldInfo(fieldName, containingObjectName);

            EntityField2 ent = new EntityField2(fieldInfo);
            Predicate predicate = ent == valueTextBox;
            predicateExpression.Add(predicate);
            filter.Add(predicateExpression);
            bucket.PredicateExpression.Add(filter);

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 28-Aug-2007 17:06:43   
//get the values from the dropdown selecteditem
string fieldName = "OrderId";
string containingObjectName = "OrderEntity";

IRelationPredicateBucket bucket = new RelationPredicateBucket();
PredicateExpression filter = new PredicateExpression();
IPredicateExpression predicateExpression = new PredicateExpression();
            
EntityField2 ent = EntityFieldFactory.Create(containingObjectName, fieldName);
Predicate predicate = ent == valueTextBox;
predicateExpression.Add(predicate);
filter.Add(predicateExpression);
bucket.PredicateExpression.Add(filter);

which could be simpifilied to this

//get the values from the dropdown selecteditem
string fieldName = "OrderId";
string containingObjectName = "OrderEntity";

EntityField2 ent = EntityFieldFactory.Create(containingObjectName, fieldName);
IRelationPredicateBucket bucket = new RelationPredicateBucket(ent == valueTextBox);
JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 28-Aug-2007 17:33:29   

Not OP, but was interested. Need to make EntityField2 IEntityField2 to make it compile.

(edit) and then cast the ent to EntityField2.


            string fieldName = "OrderId";
            string containingObjectName = "OrderEntity";

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