문제

I have the following code:

        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;
        }

The problem I am facing is that the MessageBox does not load, I have made sure there are two pieces of data that should be caught it never gets there. Can anyone help me on why my code isn't working.

Thanks.

도움이 되었습니까?

해결책

Try this

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());
        }
    };
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top