这是我的日程安排课
[Table("Schedules", Schema = "Expedia")]
public class Schedule
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ScheduleId { get; set; }
[ForeignKey("Inventory")]
public int FlightId { get; set; }
public FlightInventory Inventory { get; set; }
[Display(Name = "Departure city")]
public string DepartureCity { get; set; }
[Display(Name = "Arrival city")]
public string DestiationCity { get; set; }
[Display(Name = "Departure date")]
[Required]
public string DepartureDate { get; set; }
[Required]
[Display(Name = "Arrival date")]
public string ArrivalDate { get; set; }
[Required]
[Display(Name = "Departure Time")]
public string Departure { get; set; }
[Required]
[Display(Name = "Arrival Time")]
public string Arrival { get; set; }
[Display(Name = "Price/Ticket")]
public int Price { get; set; }
}
}
这是我的上下文类
public class UsersContext : DbContext
{
public UsersContext()
: base("Expedia") { }
public DbSet<Schedule> schedules { get; set; }
}
这是我的函数返回查询结果:
public dynamic Details(int ScheduleID)
{
var query =(from f in db.schedules.Where(f => f.ScheduleId== ScheduleID)
select new
{
f.ScheduleId,
f.DepartureDate,
f.ArrivalDate,
f.Departure,
f.Arrival,
f.DepartureCity,
f.DestiationCity,
f.Inventory.provider,
f.Inventory.nonstop,
f.Price,
f.Inventory.Available
}).ToList();
return query.AsEnumerable();
}
当我在我的控制器中调用它时:
var result= x.Details(selectedID);
尽管查询返回一个值,但结果变量显示null
值。
如何访问控制器中的查询结果?
请提供任何链接、参考、提示。