Will Entity Framework 6 function normally within Task.Run() statements?

c# entity-framework-6 task-parallel-library

Question

My question is simple, if I perform a read or write within a Task. Will the code I run to make my procedure asynchronous function as it would normally, or is there anything with EF that forbids this practise?

For instance:

await Task.Run(() =>
{
    var data = _context.KittenLog.ToList();
}

I have a sneaking suspicion that doing this may lead to trouble, but I can't locate any information regarding merging the two on Google.

1
4
2/17/2017 3:35:40 PM

Accepted Answer

You certainly could. But there is no need to include a call to action.Task.Run Since it includes native async capabilities, consider it asynchronous (see https://msdn.microsoft.com/en-us/library/jj819165(v=vs.113).aspx#Making).

In your situation, it will resemble:

var data = await _context.KittenLog.ToListAsync(CancellationToken.None);

There are a few things to think about. similar to how just one async action may be handled by the context at once.

5
2/17/2017 4:04:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow