帮助EntityQuery加载

时间:2011-05-15 23:31:40

标签: c# silverlight web-services domainservices

我有以下代码:

        EntityQuery<Web.Ticket> query =
               from t in ticketClass.getQuery()
               where t.showId == selectedShowId
               select t;

        LoadOperation<Web.Ticket> loadTic = ticketClass.loadTicketsQuery(query);
        loadTic.Completed += (s, a) =>
        {
            List<int> takenSeats = new List<int>();
            foreach (Web.Ticket ticket in ticketClass.getContext())
            {
                takenSeats.Add((int)ticket.seatId);
                MessageBox.Show(ticket.seatId.ToString());
            }
        };

getQuery:

public EntityQuery<Web.Ticket> getQuery()
        {
            return _ticketContext.GetTicketsQuery();
        }

loadTicketsQuery:

public LoadOperation<Web.Ticket> loadTicketsQuery(EntityQuery<Web.Ticket> query)
        {
            return _ticketContext.Load(query);
        }

的getContext:

public EntitySet getContext()
        {
            return _ticketContext.Tickets;
        }

我面临的问题是MessageBox没有加载,我确保有两个数据应该被捕获它永远不会到达那里。任何人都可以帮助我解释为什么我的代码无效。

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个

loadTic.Completed += (s, a) =>
    {
        List<int> takenSeats = new List<int>();
        foreach (Web.Ticket ticket in  ((LoadOperation<Web.Ticket>)s).Entities.ToList())
        {
            takenSeats.Add((int)ticket.seatId);
            MessageBox.Show(ticket.seatId.ToString());
        }
    };