mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Merging two objects into a new target instance

Open SunnyVachhetA opened this issue 1 year ago • 1 comments

Describe the bug In records, with property having get; init; is not creating update mapping in generated source code. Due to init; setter. We are using init due to coding standards.

Declaration code

public class Car
{
    public int Id { get; set; }
		
    public string Name { get; set; }
		
    public double? Price { get; set; }
}

public record CarDto
{
    public int Id { get; init; }
		
    public string Name { get; init; }
		
    public double Price { get; init; }
}

[Mapper]
public partial class CarMapper
{
    public partial void UpdateCarDto(Car car, CarDto carDto);
}

Actual relevant generated code

// Actual relevant code generated by Mapperly
// <auto-generated />
#nullable enable
public partial class CarMapper
{
    [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "3.6.0.0")]
    public partial void UpdateCarDto(global::Car car, global::CarDto carDto)
    {
    }
}

Expected relevant generated code

// The generated code how you expect it to look like
#nullable enable
public partial class CarMapper
{
    [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "3.6.0.0")]
    public partial void UpdateCarDto(global::Car car, global::CarDto carDto)
    {
        return carDto with
        {
            Id = car.Id,
            Name = car.Name,
            Price = car.Price ?? existingCarDto.Price
        };
    }
}

Environment (please complete the following information):

  • Mapperly Version: 3.6.0
  • Nullable reference types: Enabled
  • .NET Version: .NET 8.0.100
  • Target Framework: .NET 8.0.0
  • Compiler Version: '4.8.0-3.23524.11 (f43cd10b)'.
  • C# Language Version: 12.0
  • IDE: Visual Studio 17.5.4
  • OS: Windows 11

Additional context

SunnyVachhetA avatar Jul 25 '24 12:07 SunnyVachhetA

This is not really a bug, it‘s a not supported feature by Mapperly: Merging two objects into a new target instance.

latonz avatar Jul 29 '24 13:07 latonz