public ReadOnlyCollection <ILegDTO> FindDepartures(string @from, TransportType allowedTransportTypes) { UtilityClass.CheckNotNull(from); UtilityClass.CheckOnlyAlphanumChar(from); UtilityClass.CheckNameLength(from); UtilityClass.CheckTransportType(allowedTransportTypes); try { using (var travelCompanyDBContext = new TravelCompanyContext(TravelCompanyConnectionString)) { List <ILegDTO> legsDTO = new List <ILegDTO>(); var elementsLegDb = from l in travelCompanyDBContext.legs where (l.From == @from && allowedTransportTypes.HasFlag(l.TransportT)) select l; foreach (var leg in elementsLegDb) { legsDTO.Add(new LegDTO(leg.From, leg.To, leg.Distance, leg.Cost, leg.TransportT)); } return(legsDTO.AsReadOnly()); } } catch (Exception e) { throw new DbConnectionException(e.Message, e); } }