locked
Help with creating a Lambda Join and Where Expression RRS feed

  • Question

  • User-1072848465 posted

    I am exhausted in my efforts, can someone please convert this to a lambda expression?

            var getMembersInCounties = (from c in context.Members
                                        join m in context.MemberRoleDetails
                                        on c.Id equals m.MemberId
                                        where c.Active == 1
                                        where m.MemberRoleTypeId == 1
                                        where m.Active == 1
                                        where c.CountyId == 186 || c.CountyId == 192
                                        where c.email == null || c.email == ""
                                        orderby c.lastName
                                        select new
                                        {
                                            id = c.Id,
                                            familyName = c.firstName + " " + c.lastName,
                                            partnerId = c.PartnerId
                                        }).ToList();

    Thank you!

    Thursday, October 1, 2015 5:42 PM

Answers

All replies

  • User-271186128 posted

    Hi bdassow,

    As for this issue, you could refer to the following code:

                    ObjectSet<Members> members = context.Contacts;
                    ObjectSet<MemberRoleDetails> salesOrderheaders = context.SalesOrderHeaders;
                    var getMembersInCounties = members.Join(salesOrderheaders,
                        member => member.Id,
                        salesOrderheader = salesOrderheader.MemberId,
                        (member, salesOrderheader) => new { member, salesOrderheader })
                        .Where(cc => cc.member.Active == 1)
                        .Where(cc => cc.salesOrderheader.MemberRoleTypeId == 1)  //Add where clause
                        .OrderBy(cc => cc.member.LastName)
                        .Select(cc => new { id = cc.member.Id, familyName = cc.member.firstName + " " + cc.member.lastName, partnerId = cc.member.PartnerId }).ToList();
    

    For more details, you could refer to the following articles:

    https://msdn.microsoft.com/en-us/library/bb399367(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/bb896339(v=vs.110).aspx

    http://stackoverflow.com/questions/3547652/linq-join-where-clause

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 2, 2015 2:11 AM
  • User-1072848465 posted

    Thanks Dillion. You got me steered in the right direction and I have it working.

    Friday, October 2, 2015 8:25 AM