I follow Generic Repository Pattern in ASP.NET Core, but on IRepository
, I use IQueryable
instead of IEnumerable
:
publ
Entity Framework DbContext
is not thread safe. You can execute only one query at a time otherwise you will get an exception like you did above.
I suppose that you use our repository multiple times during same request in parallel that's why you get the exception. If you don't create a transaction per request you can simply make repository transient. In this case new repository will be created fro each instance of your service and you will avoid concurrency issue.