2

I'm developing a new application using entity framework 6.1. This time I'm using async methdos for everything inside my repository class. It means that I'm not using SaveChanges(), ToList(), Count(), but SaveChangesAsync(), ToListAsync(), CountAsync() instead.

I made a research to find out the right time to use the async operations. The problem is that some articles says to ALWAYS use async operations if possible (considering EF 6.1), it may not show any difference in simple scenarios, but today async is always a good choice.

However, some articles says that DbContext class is a little bit messy when the subject is async queries, and you should be careful when choosing async operations...

Finally, after hours of researches, I still don't know if I can use async operations without problems (considering an up to date version of EF)... some say yes, some say no... So, my question is "Can I use async operations to every database query without problems?"

Hope that I was clear about my problem.

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
Fabio
  • 11,892
  • 1
  • 25
  • 41
  • IMHO, Yes, you can... but you should use async only when you need it... because if you don't need parallel run, async only complicates and decrease performance – Arsen Mkrtchyan Apr 17 '15 at 12:09
  • Watch out: http://stackoverflow.com/q/28543293/861716 – Gert Arnold Apr 17 '15 at 12:12
  • @ArsenMkrt When do I need parallel run? queries against tables with large amount of data, right? or maybe the most called queries? – Fabio Apr 17 '15 at 12:53
  • when you want to do two or more things at the same time... parallel run doesn't improve performance when you need to wait the result each time, after run – Arsen Mkrtchyan Apr 17 '15 at 13:10
  • 1
    yeah but my point is, in a web app, using async queries the IIS remains available for other incoming requests while the data are fetching... so, in my case, is there a problem using async queries for everything? because I don't know exactly which queries will take more time and which won't – Fabio Apr 17 '15 at 14:44

1 Answers1

0

The new Async model designed for cases when all your code and application architecture based on ASYNC model... then you can use async methods..

In case if you are using not async model.. better way will be to use not async methods because you will never know if your async code in non-async context will work properly.

Andrii Tsok
  • 1,386
  • 1
  • 13
  • 26