public MyEntityInput GetMyEntityDetailsforEditRepo(EntityDto input)
{
var MyEntityDetails = ObjectMapper.Map<MyEntityInput>(Get(input.Id));
var MyChildEntity = from tjs in _myChildMyEntityAssociationRepository.GetAll()
join tj in _myChildEntityRepository.GetAll() on tjs.MyChildEntityId equals tj.Id
where tjs.MyEntityId == input.Id
select new MyChildEntityDetailsDto
{
Id = tj.Id,
MyChildEntityCode = tj.MyChildEntityCode,
MyChildEntityDesc = tj.MyChildEntityDesc,
MyChildEntityName = tj.MyChildEntityName
};
MyEntityDetails.MyChildEntity = ObjectMapper.Map<List<MyChildEntityDetailsDto>>(MyChildEntity);
return MyEntityDetails;
}
Getting the below exception, while calling the above method.
INFO 2017-12-22 09:08:26,189 [25 ] pNetCore.Cors.Infrastructure.CorsService - Policy execution successful. INFO 2017-12-22 09:08:26,227 [22 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method MyCompany.MyProject.Business.Services.MyEntitys.MyEntityAppService.GetMyEntityDetailsforEdit (MyCompany.MyProject.Business.Services) with arguments (Abp.Application.Services.Dto.EntityDto) - ModelState is Valid INFO 2017-12-22 09:08:28,835 [25 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method MyCompany.MyProject.Business.Services.Common.CommonAppService.GetLookupItems (MyCompany.MyProject.Business.Services) with arguments (MyCompany.MyProject.Business.Dto.Common.GetLookupInput) - ModelState is Valid INFO 2017-12-22 09:09:16,443 [25 ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext. INFO 2017-12-22 09:09:16,449 [25 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action MyCompany.MyProject.Business.Services.Common.CommonAppService.GetLookupItems (MyCompany.MyProject.Business.Services) in 50348.6255ms INFO 2017-12-22 09:09:16,477 [25 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 50385.6354ms 200 application/json; charset=utf-8 ERROR 2017-12-22 09:09:16,480 [22 ] Mvc.ExceptionHandling.AbpExceptionFilter - There is already an open DataReader associated with this Command which must be closed first. System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. at System.Data.SqlClient.SqlInternalConMyCompanytionTds.ValidateConMyCompanytionForExecute(SqlCommand command) at System.Data.SqlClient.SqlInternalTransaction.Rollback() at System.Data.SqlClient.SqlTransaction.Dispose(Boolean disposing) at System.Data.Common.DbTransaction.Dispose() at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Dispose() at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Dispose(IIocResolver iocResolver) in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\DbContextEfCoreTransactionStrategy.cs:line 84 at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.DisposeUow() in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\EfCoreUnitOfWork.cs:line 143 at Abp.Domain.Uow.UnitOfWorkBase.Dispose() in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 296 at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.<OnActionExecutionAsync>d__4.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.AspNetCore\AspNetCore\Mvc\Uow\AbpUowActionFilter.cs:line 51 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext() INFO 2017-12-22 09:09:16,503 [22 ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext. INFO 2017-12-22 09:09:16,516 [22 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action MyCompany.MyProject.Business.Services.MyEntitys.MyEntityAppService.GetMyEntityDetailsforEdit (MyCompany.MyProject.Business.Services) in 50358.9931ms INFO 2017-12-22 09:09:16,559 [22 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 50467.3493ms 500 application/json; charset=utf-8
14 Answer(s)
-
0
hi,
try to add the red codes...
<span style="color:#FF0000">[UnitOfWork]</span> public **<span style="color:#FF0000">virtual</span>**MyEntityInput GetMyEntityDetailsforEditRepo(EntityDto input) { ... }
-
0
Tried but still the same issue.
Tried this code:
using Abp.Domain.Uow; [UnitOfWork] public virtual MyEntityInput GetMyEntityDetailsforEditRepo(EntityDto input) {
-
0
Any updates?
-
0
Any updates?
-
0
What's the implementation of CommonAppService.GetLookupItems?
-
0
@ManojReddy,
Could it be same with this one <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1858">https://github.com/aspnetboilerplate/as ... ssues/1858</a> ?
-
0
@aaron
public Dictionary<int, List<TaxonomyItemsLocDto>> GetLookupItems(GetLookupInput input) { var lookup = _commonRepository.GetAll() .Include(i => i.TaxonomyItems).Select(a=>a) .Where(p => input.MasterIds.Contains(p.TaxonomyMasterId) && p.AbpLanguages.Name == input.LanguageCode) .OrderBy(p => p.SortOrder) .ToList(); var lookups = new List<TaxonomyItemsLocDto>(ObjectMapper.Map<List<TaxonomyItemsLocDto>>(lookup)); Dictionary<int, List<TaxonomyItemsLocDto>> _lookup = new Dictionary<int, List<TaxonomyItemsLocDto>>(); foreach (var l in lookups) { if (_lookup.ContainsKey(l.TaxonomyMasterId)) { _lookup[l.TaxonomyMasterId].Add(l); } else { _lookup.Add(l.TaxonomyMasterId, new List<TaxonomyItemsLocDto>() { new TaxonomyItemsLocDto() { TaxonomyItemLocDesc = l.TaxonomyItemLocDesc, TaxonomyMasterId = l.TaxonomyMasterId, TaxonomyItemsId = l.TaxonomyItemsId, TaxonomyItems = l.TaxonomyItems } }); } } return _lookup; }
-
0
- Are you using multiple threads (like in the issue linked by @ismcagdas), or not awaiting async Tasks properly?
- How are MyEntityAppService.GetMyEntityDetailsforEdit and CommonAppService.GetLookupItems related?
-
0
I'm not using multiple threads.
I have tried again by hitting API from Swagger UI, Logs do not have CommonAppService.GetLookupItems. in code also I check there is no relationship with CommonAppService.GetLookupItems.
Please find the logs.
Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext. INFO 2017-12-25 10:56:42,358 [3 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action MyCompany.MyProject.Business.Services.MyEntitys.MyEntityAppService.GetMyEntityDetailsforEdit (MyCompany.MyProject.Business.Services) in 493.533ms INFO 2017-12-25 10:56:42,430 [3 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 538.2111ms 500 application/json; charset=utf-8 INFO 2017-12-25 10:57:47,616 [30 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET <a class="postlink" href="http://localhost:22742/api/services/app/MyEntity/GetMyEntityDetailsforEdit?Id=3">http://localhost:22742/api/services/app ... rEdit?Id=3</a>
INFO 2017-12-25 10:57:47,625 [30 ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token. INFO 2017-12-25 10:57:47,628 [30 ] uthentication.JwtBearer.JwtBearerHandler - AuthenticationScheme: Bearer was successfully authenticated. INFO 2017-12-25 10:57:47,658 [30 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method MyCompany.MyProject.Business.Services.MyEntitys.MyEntityAppService.GetMyEntityDetailsforEdit (MyCompany.MyProject.Business.Services) with arguments (Abp.Application.Services.Dto.EntityDto) - ModelState is Valid ERROR 2017-12-25 10:57:48,185 [31 ] Mvc.ExceptionHandling.AbpExceptionFilter - There is already an open DataReader associated with this Command which must be closed first. System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. at System.Data.SqlClient.SqlInternalConMyCompanytionTds.ValidateConMyCompanytionForExecute(SqlCommand command) at System.Data.SqlClient.SqlInternalTransaction.Rollback() at System.Data.SqlClient.SqlTransaction.Dispose(Boolean disposing) at System.Data.Common.DbTransaction.Dispose() at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Dispose() at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Dispose(IIocResolver iocResolver) in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\DbContextEfCoreTransactionStrategy.cs:line 84 at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.DisposeUow() in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\EfCoreUnitOfWork.cs:line 143 at Abp.Domain.Uow.UnitOfWorkBase.Dispose() in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 296 at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.<OnActionExecutionAsync>d__4.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.AspNetCore\AspNetCore\Mvc\Uow\AbpUowActionFilter.cs:line 51 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext() INFO 2017-12-25 10:57:48,197 [31 ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext. INFO 2017-12-25 10:57:48,216 [31 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action MyCompany.MyProject.Business.Services.MyEntitys.MyEntityAppService.GetMyEntityDetailsforEdit (MyCompany.MyProject.Business.Services) in 564.9765ms INFO 2017-12-25 10:57:48,262 [31 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 613.1618ms 500 application/json; charset=utf-8 -
0
Also,
If I comment the below line, it does not give any exception.
MyEntityDetails.MyChildEntity = ObjectMapper.Map<List<MyChildEntityDetailsDto>>(MyChildEntity);
-
0
That's what I suspected. Try doing:
MyEntityDetails.MyChildEntity = MyChildEntity.ToList();
-
0
@Aaron
Thanks it worked.
But I didn't get the reason that why it was not working.
-
0
It's a problem that AutoMapper has with ORMs when trying to map an IQueryable to a List. Related issue: https://github.com/AutoMapper/AutoMapper/issues/1517
In this case, even if it worked, it was unnecessary overhead to perform a Map since you already had MyChildEntityDetailsDto.
-
0
@Aaron
I agree, Thanks a lot :)