Support forum for ASP.NET Zero (https://aspnetzero.com/).
By System15
#31997 Following the asp.net zero documentation step by step guide I have an issue getting the following code snippet to work
Code: Select all        public ListResultDto<PersonListDto> GetPeople(GetPeopleInput input)
        {
                var allPersons = _personRepository
                .GetAll()
                .Include(p => p.Phones)
                .OrderBy(p => p.Name)
                .ThenBy(p => p.Surname)
                .ToList();

                return new ListResultDto<PersonListDto>(ObjectMapper.Map<List<PersonListDto>>(allPersons));
        }


I've added this line of code to the CustomDtoMapper.cs
Code: Select all            //Phone
            configuration.CreateMap<Phone, PhoneInPersonListDto>();


I get the error message when I try to use the GetPeople method.: "System.InvalidCastException: 'Specified cast is not valid.'" and I don't know how to resolve the issue. Any help would be much appreciated.
By System15
#32002 System.InvalidCastException
HResult=0x80004002
Message=Specified cast is not valid.
Source=Microsoft.EntityFrameworkCore.Relational
StackTrace:
at Microsoft.EntityFrameworkCore.Storage.Internal.UntypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, Func`2 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32 includeId, INavigation navigation, INavigation inverseNavigation, IEntityType targetEntityType, IClrCollectionAccessor clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter, Boolean tracking, Object entity, Func`1 relatedEntitiesFactory)
at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include[TEntity](QueryContext queryContext, TEntity entity, Object[] included, Action`3 fixup)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at DentsplyDemoNg5.PhoneBook.PersonService.GetPeople(GetPeopleInput input) in C:\Users\x\Documents\DentsplyDemoNg5\src\DentsplyDemoNg5.Application\PhoneBook\PersonService.cs:line 39
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()