我遇到错误“无法序列化接口(interface) System.Linq.IQueryable”。当我尝试在我的网络服务中运行我的方法时。我的类(class)是这样的:
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 和 returning .ToList(),但大部分都失败了
最佳答案
我不认为
您可以使用 Iqueryable 或 Ienumerable,因为它们都执行延迟执行并且不可序列化。仅当您遍历集合时才执行查询。因此将查询返回给调用者并要求他在结束时进行迭代是没有意义的。您需要传递 List
或 Array
.
您可能需要将返回类型更改为 List<Type>
关于c# - 无法序列化接口(interface) System.Linq.IQueryable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7523744/