无法序列化System.Linq.IQueryable接口

Hri*_*kan 3 c# linq asp.net-mvc

我遇到了一个错误,"无法序列化System.Linq.IQueryable接口." 当我尝试在我的Web服务中运行我的方法时.我的班级是这样的:

        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;


    }
Run Code Online (Sandbox Code Playgroud)

我已经尝试了IQueryable,IList并返回.ToList(),但大部分都证明是不成功的

Ash*_*ohn 6

我不认为你可以使用Iqueryable或Ienumerable,因为它们都执行延迟执行并且不可序列化.只有当你遍历集合时才会执行查询.因此将查询返回给调用者并要求他迭代作为他的结束是没有意义ListArray.你需要传递一个或一个.

您可能需要将返回类型更改为 List<Type>