Click here to Skip to main content
15,847,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I want to write a linq to sql query. the query that I want to implement is:

SQL
SELECT lbl.STATUS, lbl.TYPE 
FROM LABELS as lbl
JOIN RECORDS as rec ON lbl.ID = rec.LABELID
WHERE rec.STATUS == 0 OR rec.STATUS == 1 or rec.STATUS == 2


I have tried

C#
var trackingQuery = from t in dbContext.LABELS
                    from r in dbContext.RECORDS.Where(a => a.recStatus.Value = 0 || a.recStatus.Value = 1 || a.recStatus.Value = 2)
                    select new
                    {
                      t.STATUS,
                      t.TYPE
                    }


I am having "Operator '||' cannot be applied to operands of type 'int' and 'int'" this error but couldnt resolve this. Can someone help me out? Thanks
Posted
Updated 3-Jan-12 6:37am
v2

Try a.rmaStatus.Value = 0...
 
Share this answer
 
Comments
Mehdi Gholam 31-Dec-11 0:58am    
What I would have said also, 5'ed
wonder-FOOL 3-Jan-12 11:35am    
I have applied a.rmaStatus.Value = 0. The error message is similar but this time instead of nullable int it is replaced with just int. "Operator '||' cannot be applied to operands of type 'int' and 'int'".
You need to use == instead of =

e.g

C#
var trackingQuery = from t in dbContext.LABELS
                    from r in dbContext.RECORDS.Where(a => a.recStatus.Value == 0 || a.recStatus.Value == 1 || a.recStatus.Value == 2)
                    select new
                    {
                      t.STATUS,
                      t.TYPE
                    }
 
Share this answer
 
Comments
wonder-FOOL 3-Jan-12 11:57am    
Thanks Dylan. what a carelessness of mine.. i hope 2012 wont continue like this :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900