I'm running into this issue where I get the following error:
A first chance exception of type 'System.ObjectDisposedException' occurred in EntityFramework.dll
Additional information: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
I get that error while trying to access a table using EF 6. I have set the method to async and await the return value, but it still gives me disposed error.
public async Task<List<Ticket>> GetAllOpenTwoTicketsAsync() {
using (AssetTrackingEntitiesObj _edmObj = new AssetTrackingEntitiesObj()) {
_edmObj.FullObjectContext.Connection.Open();
return await _edmObj.Tickets
.Where(t => t.TicketStatusType.isOpenTicket)
.Include(t => t.AssetTickets)
.Select(t => t).ToListAsync();
}
}
here is the method that calls the tickets
TicketsCollection = new ObservableCollection<Ticket>(await _ticketRepository.GetAllOpenTwoTicketsAsync());
Am I doing that correctly? Every method in my repository uses a using statement, creates its own objectcontext, opens its own connection and then does what ever it needs to, is this the correct manner for multiple async with EF6? Thanks in advance.