SQL like outer join using LINQ

This is a discussion on SQL like outer join using LINQ within the C# Programming forums, part of the General Programming Boards category; I am not big on sql but did a project recently and did some test code on a mysql database. ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    SQL like outer join using LINQ

    I am not big on sql but did a project recently and did some test code on a mysql database. From what I remember, if you have say 5 items in table A, and three items in table B, and you join them with A being the outer source and B being the inner, and say there are only two items that match the criteria yo want, you would get something like this

    A B
    value Null
    value value
    value Null
    value value

    where the rows with botch values are the rows that match the chriteria, and the rows with null are not.

    In C# linq, if you do a join either way (seems that it doesn't matter which you choose to be the outer or inner source) it discards the non-matching ones automatically since they are objects.

    Is there a way to keep those matches even if they are null?
    Last edited by indigo0086; 08-12-2008 at 04:34 AM.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    A quick search on google revealed this. I've never done outer joins in linq myself, but it seems to explain how to do it, "DefaultIfEmpty" being the key.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Nice.

    I really like linq. Keeps me from getting disconnected if I want to do sql queries. I'm sure there's a lot you can do with sql but I like not having to jump in and out of the thing. Seems almost as powerful.
    Here to Deceive, Inveigle, Obfuscate Since 1945

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Please help create a loop for embedded SQL
    By cjohnman in forum C Programming
    Replies: 4
    Last Post: 04-24-2008, 06:46 AM
  3. Embedded SQL
    By sarac in forum C Programming
    Replies: 1
    Last Post: 05-04-2006, 09:09 AM
  4. C bubble sort?
    By fredanthony in forum C Programming
    Replies: 11
    Last Post: 02-13-2006, 08:54 PM
  5. Problem with embedded SQL in C/C++ (ECPG)
    By NeuralClone in forum C Programming
    Replies: 4
    Last Post: 10-21-2005, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21