Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating bitwise operator in LINQ to SQL?

I want to get this query at last:

 select * from tableName where columnName & 2 = 2 and columnName & 4 = 4

How can I use LINQ to generate this script?

like image 643
Saeed Neamati Avatar asked Feb 21 '26 10:02

Saeed Neamati


2 Answers

You can do bitwise operations in C# ( and in LINQ queries ) with either & or | depending on what bitwise operation you want.

var query =
            from row in context.tableName
            where (row.columnName & 2) == 2 && (row.columnName & 4) == 4
            select row
like image 126
Filip Ekberg Avatar answered Feb 23 '26 23:02

Filip Ekberg


var query = from r in context.tableName 
    where r.columnName & 2 == 2 and r.columnName & 4 == 4
    select r;
like image 41
Patrick McDonald Avatar answered Feb 24 '26 00:02

Patrick McDonald