none
Help on Right Outer Join RRS feed

  • Question

  • Hi All,

    I need a help in converting following tsql to linqtosql statement.

    "SELECT SiteCategory.Alias AS CategoryAlias, SiteSubCategory.Alias AS SubCategoryAlias FROM SiteSubCategory INNER JOIN SubCategory ON SiteSubCategory.SubCategory_Id = SubCategory.Id RIGHT OUTER JOIN Category INNER JOIN SiteCategory ON Category.Id = SiteCategory.Category_Id ON SubCategory.Category_Id = Category.Id WHERE (SiteCategory.Site_Id ='8f66a22d-1152-43ef-8dd7-fc9a0d67dfbe')"

    I request to any one help me, since I have not being able to do it since 2 hours? Some places I could even see that Outer join is not possible in LinqtoSql. Is it true?

    Regards
    Venkatesh G

    Friday, July 10, 2009 2:07 PM

Answers

  • The following should do the trick:


    from c in Categories
    from sc in c.SiteCategories
    from sub in c.SubCategories.DefaultIfEmpty()
    select new
    {
        CategoryAlias = sc.Alias,
        SubCategoryAliases = sub.SiteSubCategories.Select (ssc => ssc.Alias)
    }


    It translates into two left outer joins - which accomplish the same thing.

    Joe
    Write LINQ queries interactively - www.linqpad.net
    Saturday, July 11, 2009 1:30 PM
    Answerer

All replies

  • The following should do the trick:


    from c in Categories
    from sc in c.SiteCategories
    from sub in c.SubCategories.DefaultIfEmpty()
    select new
    {
        CategoryAlias = sc.Alias,
        SubCategoryAliases = sub.SiteSubCategories.Select (ssc => ssc.Alias)
    }


    It translates into two left outer joins - which accomplish the same thing.

    Joe
    Write LINQ queries interactively - www.linqpad.net
    Saturday, July 11, 2009 1:30 PM
    Answerer
  • Thank you Joe,

    It works fine.
    Monday, July 13, 2009 5:02 AM