我遇到了一个错误,“无法序列化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;
}
我已经尝试过IQueryable,IList并返回.ToList(),但大部分已证明是不成功的
答案 0 :(得分:6)
List
或{{1 }}
您可能需要将返回类型更改为Array
答案 1 :(得分:2)
怎么样
public IEnumerable<AirlineSearchStrong> SearchFlight(string dep_Date, string dep_Airport, string arr_Airport, int no_Of_Seats)
{
...
return query.ToList();
}
您尝试序列化数据的表示形式,linq查询本身,而不是执行查询所产生的数据,这就是为什么它不起作用。
您需要将linq查询枚举到可枚举集中,并对其进行序列化。
AirlineSearchStrong
可能需要标记为[Serializable()]