views:

144

answers:

3

Hi Following query is not working is there any problem with it?

var possibleSegments = 
    from epl in eventPotentialLegs
    join sd in segmentDurations on 
        new { 
            epl.ITARequestID, 
            epl.ITASliceNumber, 
            epl.DepartAirportAfter, 
            epl.AirportId_Origin, 
            epl.AirportId_Destination 
        } 
        equals 
        new { 
            sd.ITARequestId, 
            sd.SliceIndex, 
            sd.OriginAirport, 
            sd.DestinationAirport 
        }
    where
        epl.DepartAirportAfter > sd.UTCDepartureTime 
        and 
        epl.ArriveAirportBy > sd.UTCArrivalTime
    select new PossibleSegments{ ArrivalTime = sd.arrivalTime };
A: 

Your and should be a && in the where clause.

where epl.DepartAirportAfter >  sd.UTCDepartureTime 
and epl.ArriveAirportBy > sd.UTCArrivalTime

should be

where epl.DepartAirportAfter >  sd.UTCDepartureTime 
&& epl.ArriveAirportBy > sd.UTCArrivalTime
p.campbell
+3  A: 

what do you mean, when you say it's not working?

  new { 
        epl.ITARequestID, 
        epl.ITASliceNumber, 
        epl.DepartAirportAfter, 
        epl.AirportId_Origin, 
        epl.AirportId_Destination 
    } 
    equals 
    new { 
        sd.ITARequestId, 
        sd.SliceIndex, 
        sd.OriginAirport, 
        sd.DestinationAirport 
    }

The above clearly is not good. You have 5 parameters on left side & 4 parameters on right side. Also, you need not new an anonymous object for on clause.

The above could be written as

var possibleSegments = 
    from epl in eventPotentialLegs
    join sd in segmentDurations on 
    epl.ITARequestID = sd.ITARequestID and epl.ITASliceNumber = sd.SliceIndex
    and ... // add remaining 3 criteria for join
    where .... // continue with where clause
shahkalpesh
+1  A: 

why r u making things complex. try simple like :

var possibleSegments = 
    from epl in eventPotentialLegs
    join sd in segmentDurations on 
    epl.ITARequestID = sd.ITARequestID and epl.ITASliceNumber = sd.SliceIndex
    and epl.DepartAirportAfter = sd.OriginAirport 
    and epl.AirportId_Origin = sd.DestinationAirport
    and epl.AirportId_Destination = sd.ColumnName
    where //Your Conditions
    Select //What you want to select
Johnny