FieldCompareValuePredicate and variables

Posts   
 
    
Posts: 15
Joined: 13-Mar-2011
# Posted on: 22-Mar-2011 00:46:55   

I have a question about FieldCompareValuePredicate. It seems that you need to use an interger literal in camparisons. When I run the following code,


        public EntityCollection<ProductEntity> GetProductsWithCostAbove(int cost)
        {
            EntityCollection<ProductEntity> products = new EntityCollection<ProductEntity>();
            IPredicateExpression predEx = new PredicateExpression();
            FieldCompareValuePredicate filterElement = (FieldCompareValuePredicate)(ProductFields.StandardCost > cost);
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            
            predEx.Add(filterElement);
            bucket.PredicateExpression.Add(predEx);

            using (DataAccessAdapter adapter = DataAccess.AdaptorFactory.GetNewAdaptor(true))
            {
                adapter.FetchEntityCollection(products, bucket);
            }

            return products;
        }

, products with a standard cost greater than the cost parameter are still included in the ResultSet.

The filter does work if I hard-code a number in there e.g. ProductFields.StandardCost > 300

Is this correct? Does it only work for hard-coded literals?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Mar-2011 03:48:45   

onefootswill wrote:

, products with a standard cost greater than the cost parameter are still included in the ResultSet.

Isn't that actually expected?

onefootswill wrote:

The filter does work if I hard-code a number in there e.g. ProductFields.StandardCost > 300

Is this correct? Does it only work for hard-coded literals?

It works with any valid object (constant, variable, constant, method return value, etc.) . Maybe you are missing something in your code, plead double check.

David Elizondo | LLBLGen Support Team
Posts: 15
Joined: 13-Mar-2011
# Posted on: 23-Mar-2011 06:07:35   

Hi Daelmo,

Sorry. A typo. In:

, products with a standard cost greater than the cost parameter are still included in the ResultSet.

I meant

, products with a standard cost less than the cost parameter are still included in the ResultSet.

I double checked my code and also reverted it to it's original form using a decimal instead of an int for the cost parameter.


        public EntityCollection<ProductEntity> GetProductsWithCostAbove(decimal cost)
        {
            EntityCollection<ProductEntity> products = new EntityCollection<ProductEntity>();
            IPredicateExpression predEx = new PredicateExpression();
            FieldCompareValuePredicate filterElement = (FieldCompareValuePredicate)(ProductFields.StandardCost > cost);
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            
            predEx.Add(filterElement);
            bucket.PredicateExpression.Add(predEx);

            using (DataAccessAdapter adapter = DataAccess.AdaptorFactory.GetNewAdaptor(true))
            {
                adapter.FetchEntityCollection(products, bucket);
            }

            return products;
        }

With a parameter of 300, I am getting results with standard costs that are less than 300.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Mar-2011 06:30:52   

Sorry, I can't reproduce it. It works just fine for me. What LLBLGen version and Runtime Library version are you using? (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722)

David Elizondo | LLBLGen Support Team
Posts: 15
Joined: 13-Mar-2011
# Posted on: 25-Mar-2011 01:04:29   

Hi Daelmo,

I have sorted this out now. I was not databinding the grid on the View.

It's a strange situation where an integer literal will work without having to re-bind the grid, whereas a variable does not.

Apologies for the silly mistake.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Mar-2011 05:40:05   

Good you sorted it out. Weird indeed, maybe you can find something out there in the VSNet community wink

David Elizondo | LLBLGen Support Team