Boolean comparisons in Predicates (WHERE clause)...

Posts   
 
    
JSobell
User
Posts: 145
Joined: 07-Jan-2006
# Posted on: 16-Apr-2008 06:46:09   

Hi, I know similar questions to this have been asked before, but I can't find a solution mentioned in the forums.

We have a requirement to restrict the results of a query based on a boolean mask (for a security implementation) under MS SQL Server.

A simplified query might be: "SELECT * FROM myTable WHERE (permission & sunglasses <> 0"

How is this expressed in a predicate expression in LLBLGen? I understand that Oracle doesn't support the bitwise commands, and that's fine; we only need an MS-SQL solution simple_smile

Cheers, Jason

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 11:51:26   

The filter should look like the following (un-tested code):

PredicateExpression filter = new PredicateExpression();
int attributes = 8; 

IExpression myExpression = new Expression(MyTableFields.Permission, ExOp.BitwiseAnd, attributes);
IEntityField2 myField = MyTableFields.Permission.SetExpression(myExpression);

filter.Add(myField != 0);
JSobell
User
Posts: 145
Joined: 07-Jan-2006
# Posted on: 18-Apr-2008 02:34:41   

With a little modification this works nicely, thanks.

Cheers, Jason