views:

60

answers:

3

Hi,

I am trying to craft a LINQ statement as follows:

The result should follow between two dates (today basically) OR the result should have a "batchstatus" column that equals false (hasn't been verified yet) the result should have a "ready" column that equals true (is ready to be verified).

So verifiers can see all data from today regardless if its been verified or not, BUT shouldn't see any that the users are not ready to be seen yet.

I have tried this several different ways such as:

Dim p = From t In db.batches _
        Where t.bDate > day1 And t.bDate < day2 And t.Ready = True Or t.BatchStatus = False _
            Order By t.BatchStatus Ascending _
            Select t

Please help me keep my hair; I have a handful now & I don't know how much longer I can keep from yanking it out!!!

Thanks!

+1  A: 

Use brackets. It'll make things a lot simpler. Additionally, you can use Let clauses to make your query simpler, effectively giving you "local variables" in the query. Try this - the syntax may be slightly off (I'm not a VB guy) and the logic may very well not be what you want, but it's easier to understand IMO, so should be easier to modify.

Dim p = From t In db.batches _
        Let createdToday = t.bDate > day1 And t.bDate < day2 _
        Where createdToday And (t.Ready Or Not t.BatchStatus) _
        Order By t.BatchStatus Ascending
Jon Skeet
A: 

What about:

Dim p = From t In db.batches _
        Where (t.bDate.Date = DateTime.Today Or t.BatchStatus = False) _
               And t.Ready = True _
            Order By t.BatchStatus Ascending _
            Select t
CMS
This one worked too...I can't let both be the answer? I like this one because I never used the datetime.Today before. I actually have a little function that creates 2 strings that are june 23 2009 12:00:00AM wow I feel like a dork...
wali
A: 

Thanks Jon!!! It was parenthesis in my case:

Dim p = From t In db.batches _
            Where (t.bDate > day1 And t.bDate < day2 And t.Ready = True) Or (t.BatchStatus = False And t.Ready = True) _
            Order By t.BatchStatus Ascending _
            Select t

Thanks again....hair slowly being removed from death grip...

wali