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