none
dblinq error on outer join RRS feed

  • Question

  • Given 2 tables:

    • Client(idClient, ..., idAddress)
    • Address(idAdress, ...)

    i want to list all clients, but some don't have any address recorded. So i've tried the following query, with "db" being my DataContext:


    var qClients =
       
    from c in db.Client
       join a
    in db.Address on c.IDAddress equals a.IDAddress into subset
       
    from subAdd in subset.DefaultIfEmpty()
       
    select new {
         c
    ,
         add
    = (subAdd == null) ? "no address" : subAdd.Street  + Environment.NewLine + subAdd.Zip + " " + subAdd.City + Environment.NewLine + subAdd.Country
       
    };

    This query is directly taken from msdn rules to mimic an outer join... but when i run the code, the above query gives the "variable 'subAdd' of type 'Address' referenced from scope '', but it is not defined" error.

    I can query both tables individually without problem, so it's definitely not a connection/definition problem. I also can do a "normal" inner join (only selecting clients with address defined). But i just can't get clients with (idAddress == null)

    What am i doing wrong ?

    • Moved by Leo Liu - MSFT Monday, May 9, 2011 8:11 AM Moved for better support. (From:Visual C# General)
    Friday, May 6, 2011 10:07 AM

Answers

  • Hi Pfel;

    The syntax looks correct and I tried a similar query and it worked fine. Did you copy and past the above query or did you retype it? If there is an issues with the query it most likely on this line:

    join a in db.Address on c.IDAddress equals a.IDAddress into subset

    But as it appears it is correct above.

    Fernando


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, May 9, 2011 8:27 PM

All replies

  • I am moving your thread into the  LINQ to SQL Forum for specialized support. Thanks.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 9, 2011 8:12 AM
  • Hi Pfel;

    The syntax looks correct and I tried a similar query and it worked fine. Did you copy and past the above query or did you retype it? If there is an issues with the query it most likely on this line:

    join a in db.Address on c.IDAddress equals a.IDAddress into subset

    But as it appears it is correct above.

    Fernando


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, May 9, 2011 8:27 PM
  • Hi Pfel,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 18, 2011 1:58 PM
    Moderator