views:

71

answers:

4

I have this:

    Dim compareAddress1 = (From d In db.Addresses Where d.Address1.Equals("a") And _
               d.Address2.Equals(Nothing) And _
               d.City.Equals(Nothing) And _
              d.POBox.Equals(Nothing) And _
              d.PostalCode.Equals(Nothing) And _
              d.ZipCode.Equals(Nothing))

    Dim compareAddress2 = (From d In db.Addresses Where _
                    d.Address1.Equals(_address.Address1) And _
                    d.Address2.Equals(_address.Address2) And _
                    d.City.Equals(_address.City) And _
                    d.POBox.Equals(_address.POBox) And _
                    d.PostalCode.Equals(_address.PostalCode) And _
                    d.ZipCode.Equals(_address.ZipCode))

all field in the object _address are nullable.

When I use the object, I get this query:

    SELECT [t0].[AddressID], [t0].[Address1], [t0].[Address2], [t0].[City], [t0].[CountryProvinceID], [t0].[POBox], [t0].[PostalCode], [t0].[ZipCode]
    FROM [dbo].[Address] AS [t0]
    WHERE ([t0].[Address1] = @p0) AND ([t0].[Address2] = @p1) AND ([t0].[City] = @p2) AND ([t0].[POBox] = @p3) AND ([t0].[PostalCode] = @p4) AND ([t0].[ZipCode] = @p5)
    -------------------------------
    @p0 [AnsiString]: a
    @p1 [AnsiString]: 
    @p2 [AnsiString]: 
    @p3 [AnsiString]: 
    @p4 [AnsiString]: 
    @p5 [AnsiString]:

when I hardcode the data, I got this query:

    SELECT [t0].[AddressID], [t0].[Address1], [t0].[Address2], [t0].[City], [t0].[CountryProvinceID], [t0].[POBox], [t0].[PostalCode], [t0].[ZipCode]
    FROM [dbo].[Address] AS [t0]
    WHERE ([t0].[Address1] = @p0) AND ([t0].[Address2] IS NULL) AND ([t0].[City] IS NULL) AND ([t0].[POBox] IS NULL) AND ([t0].[PostalCode] IS NULL) AND ([t0].[ZipCode] IS NULL)
    -------------------------------
    @p0 [AnsiString]: a

anyone know why? and how to I fix my issue?

+2  A: 

Scott Guthrie created an add on, that works in the debugger.

get it here

Matthew Vines
doesn'T seem to work, how can i know if the dll got loaded?
Fredou
works pretty well for me. What is the issue you are having?
Matthew Vines
+1  A: 

How about LINQ to SQL Debug Visualizer:

http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx

aquinas
+1  A: 

Give this a shot...

Dim results = db.Addresses.Where(Function(d) d.Address1.Equals(_address.Address1) And _
                                             d.Address2.Equals(_address.Address2) And _
                                             d.City.Equals(_address.City) And _
                                             d.POBox.Equals(_address.POBox) And _
                                             d.PostalCode.Equals(_address.PostalCode) And _
                                             d.ZipCode.Equals(_address.ZipCode))

Console.WriteLine(db.GetCommand(results).CommandText)

Dim compareAddresses = results.SingleOrDefault()
Scott Ivey
doesn't seem to work with SingleOrDefault
Fredou
You're right - it doesn't since SingleOrDefault isn't an IQueryable. You could swap out your code with a Where instead - that'd give you the command generated.
Scott Ivey
I just did that, updating my question soon
Fredou
i updated my example with what I was suggesting as well
Scott Ivey
I updated my question, thanks
Fredou
A: 

Are you running this linq against sql sever 2002 i have seen some strange behavior (same as yours) when running linq against sql 2000

Shrage Smilowitz