locked
How do I select using more than one parameter in a LINQ join? RRS feed

  • Question

  • I need to select on two variables for this LINQ request, however "&&" and "and" do not work as shown below. What is the correct way to accomplish this?

    var requestDetailList =
       from requests in ds.Tables[0].AsEnumerable()
       join settings in ds.Tables[1].AsEnumerable()
       on requests.Field<long>("RequestFileDetailID") equals settings.Field<long>("AlertServiceEnrollmentRequestID")    
       && settings.Field<long>("AlertServiceEnrollmentTypeID") equals AlertServiceRequestType.ClubUtilization)
       into ClubSettings
       from cs in ClubSettings.DefaultIfEmpty()
       select new AMEnrollRequestInfo_EX
       {
           FileDetailID = Convert.ToInt32(requests.Field<long>("RequestFileDetailID")),		       ClubUtilizationLimit = (cs == null) ? string.Empty : cs.Field<string>("AlertServiceEnrollmentSettingValue")
       };

    Tuesday, March 19, 2013 8:39 PM

Answers

  • You need to create an anonymous type, it will be somthing like this

    from r in ...[0]...
    join s in ...[1]...
    on new {RFD=r.Field<long>("RequestFileDetailID"),
            ASE=s.Field<long>("AlertService...")}
    equals new {RFD=s.Field<long>("Reque..."),
                ASE=Alert...
    into ClubSettings

    The two anonymous types must have identical fields (RFD and ASE in my example)

    Paul Linton

    • Marked as answer by BillyM2010 Tuesday, March 19, 2013 10:30 PM
    Tuesday, March 19, 2013 9:06 PM