Basic query with 2 where clauses problem

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 03-Oct-2008 22:20:29   

First I'd like to preface by saying keep up the good work as I find incredible potential in this Linq to LLBL thing. For a developer it is everything to make clients feel like they can get a lot of bang for their buck. If I have to type 6 lines of code to query and feel like a typist not a developer versus feeling creative by typing one line that miraculously weaves the data I need it is a big difference!

So what is happening with me now is: If I do: dim q = from p in db.person where p.username=username select p I fine it works great, but if I: dim q = from p in db.person where p.username=username and p.password=password _ select p it crashes on the next line: if q.count > 0 then with: a lot of stuff but it complains about the query generated having an alias of [] in front of lpfa_3 I would guess: SELECT DISTINCT TOP 1 COUNT(*) AS [LPAV_] FROM [mlh].[dbo].[person] [LPLA_1] WHERE ( ( ( ( [].[LPFA_3] = @LPFA_31)))) Parameter: @LPFA_31 : Boolean. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: True. "

Do you know why just adding another and phrase would stop a query from working?

Thanks,

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Oct-2008 23:36:17   

Hi Terry,

Please use **AndAlso **operator (logical short-circuit And) instead of And. Here is a little explanation.

Another thing about your query: if you just want the Count part, your query is ok. If you will need the results, I would recommend do that this way:

Dim q = (From m In metaData.Customers _
      Where m.Country = "USA" AndAlso m.City.StartsWith("A") _
      Select m).ToList()

If (q.Count > 0) Then
      For Each c As CustomersEntity In q
            Console.WriteLine(c.CompanyName)
      Next
End If

This way just one query is executed. If you first do a Count() (one query) and then you try to use the q results, another query will be executed. So, it's recommended you use the **Count **property instead, if you plan to use the results of the query wink

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 04-Oct-2008 09:00:55   

feel like a typist not a developer..

Simply brilliant simple_smile

About the And vs. AndAlso stuff: there's unfortunately not a workaround for this to build into the linq provider.

Frans Bouma | Lead developer LLBLGen Pro