Domanda

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.

È stato utile?

Soluzione

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());
        }
    };
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top