Hi, in your step-by-step example, you add the Phone entity to the GetPeople DTO to retrieve each person and their phone numbers. Suppose each person has 10 phone numbers and you wanted to sort that list by Phone Number to make it easier to read (sort by detail entity of master-detail), how can this be done? It seems like EF/LINQ may not support this. If so, how to sort the DTO prior to returning it from the appservice? see below in red. thanks.
public ListResultDto<PersonListDto> GetPeople(GetPeopleInput input) { var persons = _personRepository .GetAll() .Include(p => p.Phones) .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.Name.Contains(input.Filter) || p.Surname.Contains(input.Filter) || p.EmailAddress.Contains(input.Filter) ) .OrderBy(p => p.Name) .ThenBy(p => p.Surname) <span style="color:#FF0000">.ThenBy(p => p.Phones.Number) // ideally you would do this</span> .ToList();
return new ListResultDto<PersonListDto>(persons.MapTo<List<PersonListDto>>());
}
3 Answer(s)
-
0
Hi,
I don't remember very well if your example is supported or not, did you try it ? If so, you can also try this
public ListResultDto < PersonListDto > GetPeople(GetPeopleInput input) { var persons = _personRepository .GetAll() .Include(p => p.Phones.OrderBy(px => px.Number)) .WhereIf(!input.Filter.IsNullOrEmpty(), p => p.Name.Contains(input.Filter) || p.Surname.Contains(input.Filter) || p.EmailAddress.Contains(input.Filter) ) .OrderBy(p => p.Name) .ThenBy(p => p.Surname) .ToList();
return new ListResultDto < PersonListDto > (persons.MapTo < List < PersonListDto >> ()); }
-
0
Thank you for your suggestions. It compiles OK but unfortunately throws error per below...
INFO 2017-03-31 08:15:36,310 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET <a class="postlink" href="http://localhost:22742/api/services/app/Division/GetDivisions">http://localhost:22742/api/services/app ... tDivisions</a>
INFO 2017-03-31 08:15:36,318 [10 ] entication.JwtBearer.JwtBearerMiddleware - Successfully validated the token. INFO 2017-03-31 08:15:36,322 [10 ] entication.JwtBearer.JwtBearerMiddleware - HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Bearer. DEBUG 2017-03-31 08:15:36,322 [10 ] NetCore.StaticFiles.StaticFileMiddleware - The request path /api/services/app/Division/GetDivisions does not match a supported file type DEBUG 2017-03-31 08:15:36,322 [10 ] osoft.AspNetCore.Routing.Tree.TreeRouter - Request successfully matched the route with name '(null)' and template 'api/services/app/Division/GetDivisions'. DEBUG 2017-03-31 08:15:36,325 [10 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action tiktok.TiktokCore.Divisions.DivisionAppService.GetDivisions (tiktok.Application) INFO 2017-03-31 08:15:36,342 [10 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method tiktok.TiktokCore.Divisions.DivisionAppService.GetDivisions (tiktok.Application) with arguments ((null)) - ModelState is Valid ERROR 2017-03-31 08:15:36,350 [26 ] Mvc.ExceptionHandling.AbpExceptionFilter - The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path System.ArgumentException: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path at System.Data.Entity.QueryableExtensions.Include[T,TProperty](IQueryable1 source, Expression
1 path) at tiktok.TiktokCore.Divisions.DivisionAppService.GetDivisions() at lambda_method(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- 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.<InvokeNextExceptionFilterAsync>d__24.MoveNext() DEBUG 2017-03-31 08:15:36,358 [26 ] ore.Mvc.Internal.ControllerActionInvoker - Request was short circuited at exception filter 'Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter'. -
0
Hi,
Then probably EF/Linq does not support it or if it does I don't know how to do it :). You can search on the internet for a solution.
Thanks.