Why does mapster fail mapping when the class to map to has a property

122 views Asked by At

Hi I have the following code:

using Mapster;

var cat = new Cat("Felix", 3);

var cat2 = cat.Adapt<Cat2>();

Console.ReadKey();

public record Cat(string Name, int Age);

public record Cat2(string Name, int Age)
{
    public string NameAndAge => $"{Name} {Age}";
}

It gives the exception:

No default constructor for type 'Cat2', please use 'ConstructUsing' or 'MapWith'

I realise this is because of the Property NameAndAge but can someone explain why this is a problem and how to get around it?

0

There are 0 answers