1
我目前有:下面的代码:生成一个SQL数据库表中的所有当前“游乐设施”的列表..但是,似乎虽然有表中的数据,我无法访问它。我是否缺少初始化步骤?其他想法?LINQ to Entities初始化
using (RamRideOpsEntities myEntities = new RamRideOpsEntities())
{
var adminOptions = (from a in myEntities.AdminOptions
select new { a.ValidDate1, a.ValidDate2 }).First();
var allRides = (from r in myEntities.Rides
where (r.TimeOfCall == adminOptions.ValidDate1 ||
r.TimeOfCall == adminOptions.ValidDate2)
orderby r.TimeOfCall descending
select r).ToList();
TextBox1.Text = allRides[0].Name; // <- Seems there are no existing objects as rides[0] is out of bounds
}
请指出究竟是什么错误。 – Kath 2012-01-18 23:46:30
你尝试过'allRides.First()。Name'吗? – 2012-01-18 23:57:05
是的,我试过allRides.FirstOrDefault(),它返回null。 @Kate:问题是虽然表中有对象,但我的列表似乎并没有抓住任何一个对象。 – SHeinema 2012-01-19 00:44:14