Base solution for your next web application
Open Closed

DTO with a property as User ISSUE! #1291


User avatar
0
zokho created

Hi, I have got a DTO class defined as:

[AutoMapFrom(typeof(WorkType))]
    public class WorkTypeDto : EntityDto
    {
        public string DisplayName { get; set; }

        public bool IsDeleted { get; set; }

        public int OrderNumber { get; set; }

        public User CreatorUser { get; set; }
    }

[AbpAuthorize("Advertisement")]
        public GetWorkTypeListOutput GetWorkTypeList()
        {
            var workTypes = _workTypeRepository.GetAll().ToList();
            var workTypeList = new GetWorkTypeListOutput()
            {
                WorkTypes = Mapper.Map<List<WorkTypeDto>>(workTypes)
            };
            return workTypeList;
        }

and my Angular code is:

vm.loadWorkTypes = function () {
                abp.ui.setBusy(
                    null,
                    workTypeService.getWorkTypeList()
                    .success(function (data) {
                        vm.gridOptions.data = data.workTypes;
                        
                    })
                    .error(function (message) {
                        alert(message);
                    })
                );
            };

it is properly populate the DTO to be passed to the Angular, but for some reason it fails without showing any descriptive error message as: [object obeject] and Internal error occurred!

I narrowed down the issue and found out that the CreatorUser property is causing it. If I change its type from User class to string that will work. Any thought?


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Do not use entities in DTOs since entities are not well serializable (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Transfer-Objects#DocDtoSerializationProblems">http://www.aspnetboilerplate.com/Pages/ ... onProblems</a>). Create a UserDto and set mapping.