c# - 无法序列化接口(interface) System.Linq.IQueryable

标签 c# asp.net-mvc linq

我遇到错误“无法序列化接口(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,因为它们都执行延迟执行并且不可序列化。仅当您遍历集合时才执行查询。因此将查询返回给调用者并要求他在结束时进行迭代是没有意义的。您需要传递 ListArray .

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

关于c# - 无法序列化接口(interface) System.Linq.IQueryable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7523744/

相关文章:

asp.net-mvc - MVC 5 bundle 错误

.net - MVC3 默认模板在哪里存储用户帐户信息?

c# - 根据另一个列表的内容对列表进行排序

C# - 使用什么属性来支持使用 XMLSerializer 和 DataContractSerializer 进行序列化?

c# - JSON 反序列化格式不正确

c# - SQL Server 群集的连接字符串

c# - 如何获取 IEnumerable 的基类型

c# - CssRewriteUrlTransform 不采取

c# - 如何分割在 foreach 循环中迭代的元素

c# - 递归 Linq - 子属性的父指示?