none
LINQ query with 4 tables. RRS feed

  • Question


  • Can anyone help me write LINQ query for the following data? All tables are left outer joined.

    Thank You

    Thursday, December 19, 2013 5:20 AM

Answers

  • Hello,

    Do not understand why it needs to add so many brackets. If the sql query is like below:

    SELECT F0111.WWAN8
    
      FROM  PRODDTA.F0101 F0101  
      
      LEFT OUTER JOIN PRODDTA.F0111 F0111 ON F0101.ABAN8=F0111.WWAN8
    
      LEFT OUTER JOIN PRODDTA.F0115 F0115 ON (F0111.WWAN8=F0115.WPAN8) AND (F0111.WWIDLN=F0115.WPIDLN)
    
      LEFT OUTER JOIN PRODDTA.F01151 F01151 ON (F0111.WWAN8=F01151.EAAN8) AND (F0111.WWIDLN=F01151.EAIDLN)

    Then the linq query should be:

      var result = from F0101 in db.F0101
                                 join F0111 in db.F0111.DefaultIfEmpty() on F0101.ABAN8 equals F0111.WWAN8
                                 join F0115 in db.F0115.DefaultIfEmpty() on new { F0111.WWAN8, F0111.WWIDLN } equals new { F0115.WPAN8, F0115.WPIDLN }
                                 join F01151 in db.F01151.DefaultIfEmpty() on new { F0111.WWAN8, F0111.WWIDLN } equals new { F01151.EAAN8, F01151.EAIDLN }
                                 select F0111.WWAN8;

    The left outer join in linq query is DefaultIfEmpty().

    For join in linq, please refer to link below:

    http://msdn.microsoft.com/en-us/vstudio/bb737909

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 20, 2013 6:52 AM
    Moderator

All replies

  • Hello,

    >>Can anyone help me write LINQ query for the following data?

    From the image, we can hardly know what you want. I think you should at least give us what sql statement you want to use.

    Or you can learn the linq query from here:

    http://www.codeproject.com/Articles/286255/Using-LINQ-Queries

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 20, 2013 2:41 AM
    Moderator
  • Hello,

    >>Can anyone help me write LINQ query for the following data?

    From the image, we can hardly know what you want. I think you should at least give us what sql statement you want to use.

    Or you can learn the linq query from here:

    http://www.codeproject.com/Articles/286255/Using-LINQ-Queries

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sorry I forgot to include the query, but  the query does not matter as long as all of the tables have left outer join.

    SELECT F0111.WWAN8
     FROM   ((PRODDTA.F0101 F0101 
     LEFT OUTER JOIN PRODDTA.F0111 F0111 ON F0101.ABAN8=F0111.WWAN8) 
     LEFT OUTER JOIN PRODDTA.F0115 F0115 ON (F0111.WWAN8=F0115.WPAN8) AND (F0111.WWIDLN=F0115.WPIDLN)) 
     LEFT OUTER JOIN PRODDTA.F01151 F01151 ON (F0111.WWAN8=F01151.EAAN8) AND (F0111.WWIDLN=F01151.EAIDLN)

    Thank you for the link!


    Peter Czurak

    Friday, December 20, 2013 3:10 AM
  • Hello,

    Do not understand why it needs to add so many brackets. If the sql query is like below:

    SELECT F0111.WWAN8
    
      FROM  PRODDTA.F0101 F0101  
      
      LEFT OUTER JOIN PRODDTA.F0111 F0111 ON F0101.ABAN8=F0111.WWAN8
    
      LEFT OUTER JOIN PRODDTA.F0115 F0115 ON (F0111.WWAN8=F0115.WPAN8) AND (F0111.WWIDLN=F0115.WPIDLN)
    
      LEFT OUTER JOIN PRODDTA.F01151 F01151 ON (F0111.WWAN8=F01151.EAAN8) AND (F0111.WWIDLN=F01151.EAIDLN)

    Then the linq query should be:

      var result = from F0101 in db.F0101
                                 join F0111 in db.F0111.DefaultIfEmpty() on F0101.ABAN8 equals F0111.WWAN8
                                 join F0115 in db.F0115.DefaultIfEmpty() on new { F0111.WWAN8, F0111.WWIDLN } equals new { F0115.WPAN8, F0115.WPIDLN }
                                 join F01151 in db.F01151.DefaultIfEmpty() on new { F0111.WWAN8, F0111.WWIDLN } equals new { F01151.EAAN8, F01151.EAIDLN }
                                 select F0111.WWAN8;

    The left outer join in linq query is DefaultIfEmpty().

    For join in linq, please refer to link below:

    http://msdn.microsoft.com/en-us/vstudio/bb737909

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 20, 2013 6:52 AM
    Moderator