asp.net web api - EntityFrameworkCore adds Multiple values in databas with async -


i using ef core storing product information. run code unit-test real sql server works fine. when run web service using startup dependency injection on iis deadlocks exception. , multiple values(rows) in database. can´t understand difference between executions.

this code unit-test works , set 1 row in database.

var options = new dbcontextoptionsbuilder<data.contexts.workordercontext>() .usesqlserver("data source=(localdb)\\mssqllocaldb;initial catalog=workorder;integrated security=true;") .options; workordercontext context = new workordercontext(options);  data.repositories.workorder.workorderunitofwork unit = new data.repositories.workorder.workorderunitofwork(context); ilegacywrapperservice wrapperservice = new legacywrapperservicecs();  services.services.workorderservice workorderservice = new services.services.workorderservice(unit, wrapperservice);  var options2 = new dbcontextoptionsbuilder<data.contexts.productinformationcontext>() .usesqlserver("data source=(localdb)\\mssqllocaldb;initial catalog=productinformation;integrated security=true;") .options; data.contexts.productinformationcontext contextproduct = new data.contexts.productinformationcontext(options2);  data.repositories.productinformation.productinformationunitofwork unitproduct = new data.repositories.productinformation.productinformationunitofwork(contextproduct); services.services.productinformationservice productservice = new services.services.productinformationservice(unitproduct, wrapperservice);  workorderscontroller controller = new workorderscontroller(workorderservice, wrapperservice, productservice, null); var resp = await controller.getexternalrefasync(id); var resp1 = await controller.getexternalrefasync(id); var resp2 = await controller.getexternalrefasync(id);  assert.notnull(resp); 

and here startup file used when run web service

services.addsingleton<ihttpcontextaccessor, httpcontextaccessor>();  //default var connection = configuration.getconnectionstring("workorderdatabase"); services.adddbcontext<workordercontext>(options => options.usesqlserver(connection)); services.addscoped<core.data.repositories.workorderrepos.iworkordersunitofwork, data.repositories.workorder.workorderunitofwork>();  var connectionproductioninformation = configuration.getconnectionstring("productinformationdatabase"); services.adddbcontext<productinformationcontext>(options => options.usesqlserver(connectionproductioninformation)); services.addscoped<core.data.repositories.productinformationrepos.iproductsunitofwork, data.repositories.productinformation.productinformationunitofwork>();  services.addtransient<ilegacywrapperservice, legacywrapperservicecs>(); services.addtransient<iproductinformationservice, services.services.productinformationservice>();  services.addtransient<iworkorderservice, services.services.workorderservice>(); 

exception

transaction (process id 54) deadlocked on lock resources process , has been chosen deadlock victim. rerun transaction.

stacktrace

at api.controllers.workorderscontroller. d__22.movenext() in c:\api\src\api\controllers\workorderscontroller.cs:line 315 --- end of stack trace previous location exception thrown

-- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw() @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) @ system.runtime.compilerservices.taskawaiter1.getresult() @ api.controllers.workorderscontroller.<getxmlasync>d__18.movenext() in c:\api\src\api\controllers\workorderscontroller.cs:line 222 --- end of stack trace previous location exception thrown --- @ system.runtime.exceptionservices.exceptiondispatchinfo.throw() @ system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) @ microsoft.aspnetcore.mvc.internal.objectmethodexecutor.<casttoobject>d__381.movenext() --- end of ...

can need change able start application on same way or can change unit test use di configuration?


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

php - Cannot override Laravel Spark authentication with own implementation -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -