Entity Framwork 4.1 left outer join RRS feed

  • Question

  • how to perform mysql left outer join for ten tables using ado.net entity framework
    • Moved by Jie Bao Thursday, July 14, 2011 2:28 AM (From:Windows Presentation Foundation (WPF))
    Wednesday, July 13, 2011 11:03 AM

All replies

  • Hi i tried like this but i dod not get the required result. can you tel me what is the problem

    var query = from fg in _db.FGCodeTypes
                            join mt in _db.ModelTypes on fg.ModelID equals mt.ID into list1
                            from l1 in list1.DefaultIfEmpty()
                            join mc in _db.MechanismTypes on fg.MechanismID equals mc.ID into list2
                            from l2 in list2.DefaultIfEmpty()
                            join mctl in _db.MechColourTypes on fg.MechColourID equals mctl.ID into list3
                            from l3 in list3.DefaultIfEmpty()
                            join ast in _db.ArmrestTypes on fg.ArmrestID equals ast.ID into list4
                            from l4 in list4.DefaultIfEmpty()
                            join astcl in _db.ArmrestColourTypes on fg.ArmrestColourID equals astcl.ID into     list5
                            from l5 in list5.DefaultIfEmpty()
                            join bs in _db.BaseTypes on fg.BaseID equals bs.ID into list6
                            from l6 in list6.DefaultIfEmpty()
                            join bscl in _db.BaseColourTypes on fg.BaseColourID equals bscl.ID into list7
                            from l7 in list7.DefaultIfEmpty()
                            join bh in _db.BackHeightTypes on fg.BackHeightID equals bh.ID into list8
                            from l8 in list8.DefaultIfEmpty()
                            join ft in _db.FeaturesTypes on fg.FeaturesID equals ft.ID into list9
                            from l9 in list9.DefaultIfEmpty()
                            join pc in _db.PriceCategoryTypes on fg.PriceCategoryID equals pc.ID into list10
                            from l10 in list10.DefaultIfEmpty()
                            select new { l1.Name, fg.Price, fg.ID };    

    Thursday, July 14, 2011 4:39 AM
  • See this bit

                from l1 in list1.DefaultIfEmpty()
                 join mc in _db.MechanismTypes on fg.MechanismID equals mc.ID into list2

    One of them references in the join should be l1.

    I would think

                from l1 in list1.DefaultIfEmpty()
                 join mc in _db.MechanismTypes on l1.MechanismID equals mc.ID into list2

    And similarly with the other 9.

    I would also strongly recommend you start with 1 join and get that working then add another rather than type the whole lot in and not know which bit isn't working.



    "did not get the required result" isn't a very useful description of what you're seeing.


    Thursday, July 14, 2011 8:21 AM
  •  List<FGCodeType> fgCodeType = new List<FGCodeType>();
      var Type = (from fg in _db.FGCodeTypes
                       join mt in _db.ModelTypes on fg.ModelID equals mt.ID into list1
                       from l1 in list1.DefaultIfEmpty()
                       select new { l1.Name, fg.Price, fg.ID }).ToList();
    fgCodeType = Type.ToList<FGCodeType>(); is not working
    Kindly tell me the proper way
    Thursday, July 14, 2011 11:45 AM
  • Hello,

    Thank you for posting.

    From your description, I have a few questions need to clarify with you.

    1. Could you please provide more detailed error information in your reply?

    2. What's your major question want to consult? Left join in EF or others.


    Larcolais Gong[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.

    Friday, July 15, 2011 9:14 AM