Using Modulus in Predicate Expression

Posts   
 
    
KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 19-Dec-2006 18:06:15   

I am using the latest version of the LLBL and I am trying to figure out how to use modulus in my predicate expression:

bucket.PredicateExpression.AddWithAnd(amount % DenominationFields.Amount == 0);

This is not allowed. Any ideas?

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 19-Dec-2006 19:09:04   

Look in the help for v2. It is in the section Using the generated code/Field expressions and aggregates.

You need to use an expression for the left hand side of your comparison:

new Expression(amount , ExOp.Mod, DenominationFields.Amount )

KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 19-Dec-2006 20:11:02   

Ok, I get an exception saying "Mod is not supported by SqlServer"? That doesn't make sense...

Note I am using the adapter model.


        public DataTable FetchProviderOptions(int categoryID, int amount, int cutOffAmount)
        {
            ResultsetFields fields = new ResultsetFields(3);
            RelationPredicateBucket bucket = new RelationPredicateBucket();

            DataTable dtResults = new DataTable();

            // define our fields to fetch.
            fields[0] = ProviderFields.ProviderID;
            fields[1] = ProviderFields.ImageName;
            fields[2] = DenominationFields.Amount;

            // add our entity joins.
            bucket.Relations.Add(ProviderEntity.Relations.Provider_DenominationEntityUsingProviderID);
            bucket.Relations.Add(Provider_DenominationEntity.Relations.DenominationEntityUsingDenominationID);

            // build our predicates for the provider table.
            bucket.PredicateExpression.Add(ProviderFields.Active == true);
            bucket.PredicateExpression.AddWithAnd(ProviderFields.ProviderCategoryID == categoryID);
            
            // build our predicates for the denomination table.
            bucket.PredicateExpression.AddWithAnd(DenominationFields.Active == true);
            bucket.PredicateExpression.AddWithAnd(DenominationFields.Amount <= amount);
            bucket.PredicateExpression.AddWithAnd(DenominationFields.Amount >= cutOffAmount);

            IEntityField2 field = new EntityField2("Result", new Expression(amount, ExOp.Mod, DenominationFields.Amount));
            bucket.PredicateExpression.AddWithAnd(new FieldCompareValuePredicate(field, null, ComparisonOperator.Equal, 0));        

            // perform our fetch.
            base.DataAccessAdapter.FetchTypedList(fields, dtResults, bucket, 0,
                new SortExpression(ProviderFields.ProviderNm | SortOperator.Ascending) & (DenominationFields.Amount | SortOperator.Ascending), false);

            return dtResults;
        }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 19-Dec-2006 20:33:08   

I think that's a mistake on our part. The SQLServer DQE indeed filters out Mod. This is indeed incorrect, it IS supported. I'll change this in the next build of the runtime libraries, released later this week.

Frans Bouma | Lead developer LLBLGen Pro
KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 19-Dec-2006 20:35:27   

Otis wrote:

I think that's a mistake on our part. The SQLServer DQE indeed filters out Mod. This is indeed incorrect, it IS supported. I'll change this in the next build of the runtime libraries, released later this week.

Thanks, I'll just use a good ol' reverse loop and pull them out for the time being...sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Dec-2006 12:42:23   

FIxed in build 061220 of the runtime library uploaded later this week.

Frans Bouma | Lead developer LLBLGen Pro