Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot serialize interface System.Linq.IQueryable

I'm faced with an error, "Cannot serialize interface System.Linq.IQueryable." when I try to run my method in my web service. My class is as such:

        public class AirlineSearchStrong
    {
        public Flight_Schedule flightSchedule { get; set; }
        public Flight_Schedule_Seats_and_Price flightScheduleAndPrices { get; set; }
        public Airline airline { get; set; }
        public Travel_Class_Capacity travelClassCapacity { get; set; }

    }

    [WebMethod]
    public IQueryable SearchFlight(string dep_Date, string dep_Airport, string arr_Airport, int no_Of_Seats)
    {        
        AirlineLinqDataContext db = new AirlineLinqDataContext();
        var query = (from fs in db.Flight_Schedules
                     join fssp in db.Flight_Schedule_Seats_and_Prices on fs.flight_number equals fssp.flight_number
                     join al in db.Airlines on fs.airline_code equals al.airline_code
                     join altc in db.Travel_Class_Capacities on al.aircraft_type_code equals altc.aircraft_type_code

                     where fs.departure_date == Convert.ToDateTime(dep_Date)
                     where fs.origin_airport_code == dep_Airport
                     where fs.destination_airport_code == arr_Airport
                     where altc.seat_capacity - fssp.seats_taken >= no_Of_Seats
                     select new AirlineSearchStrong { 
                     flightSchedule = fs,
                     flightScheduleAndPrices = fssp,
                     airline = al,
                     travelClassCapacity = altc
                     });
            return query;


    }

I've tried IQueryable, IList and returning .ToList() but most of it has turned out to be unsuccessful

like image 631
Hriskesh Ashokan Avatar asked Jul 18 '26 00:07

Hriskesh Ashokan


1 Answers

i dont think you can use Iqueryable or Ienumerable as they both do lazy execution and are not serializable. The query gets executed only when you iterate through the collection.so it doesn't make sense to return the query to the caller and asking him to iterate as his end.you need to pass a List or an Array.

You may need to change the return type to List<Type>

like image 90
Ashley John Avatar answered Jul 20 '26 13:07

Ashley John