Base solution for your next web application
Open Closed

input.MapTo Error #3146


User avatar
0
20summers created

I am creating my first Create/Edit Modal

I keep on getting ar error on the following line: var project = input.MapTo<Project>();

I have confirmed there is definitely data that is populated in input

public class CreateOrUpdateProjectDto 
    {
               public ProjectEditDto Project { get; set; }
    }

 [AutoMapFrom(typeof(Project))]
        public class ProjectEditDto 
        {

            public int? Id { get; set; }

            public string Name { get; set; }

            public string Summary { get; set; }

            public  string ProjectNumber { get; set; }

            public  string FinanceReference { get; set; }

            public  DateTime? RegistrationDateTime { get; set; }

            public  DateTime? StartonSiteDateTime { get; set; }

            public  DateTime? ActualCompletionDateTime { get; set; }

            public  DateTime? EstimatedCompletionDateTime { get; set; }

            public  string ProjectGuid { get; set; }

            public  int? ProjectTypeId { get; set; }

            public string ProjectTypeType { get; set; }

            public string ProjectTypeText { get; set; }
    }


 [AbpAuthorize(AppPermissions.Pages_Tenant_Projects_Create)]
        public async Task CreateOrUpdateProject(CreateOrUpdateProjectDto input)
        {
            if (!input.Project.Id.HasValue)
            {
                await CreateProjectAsync(input);
            }
            else
            {
                await EditProjectAsync(input);
            }

        }

        protected virtual async Task CreateProjectAsync(CreateOrUpdateProjectDto input)
        {
            var project = input.MapTo<Project>();
            await _projectRepository.InsertAsync(project);
        }

3 Answer(s)
  • User Avatar
    0
    20summers created

    I have since changed the following line, but still not working

    var project = input.Project.MapTo<Project>();

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I'm not %100 sure but your problem might be related to mapping ocnfiguration. You are mapping your Dto to your entity but your dto contains this attribute

    [AutoMapFrom(typeof(Project))]
    

    According to this, you can map your entity to your dto not the opposite. You can simply use

    [AutoMap(typeof(Project))]
    

    If that does not solve your problem, please share the exception message as well.

    Thanks.

  • User Avatar
    0
    20summers created

    Brilliant - that worked Thanks!