Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping property with underscore to record with constructor #388

Closed
RobThree opened this issue Nov 10, 2021 · 4 comments
Closed

Mapping property with underscore to record with constructor #388

RobThree opened this issue Nov 10, 2021 · 4 comments
Assignees
Labels

Comments

@RobThree
Copy link

RobThree commented Nov 10, 2021

First of all: thanks for this great library!

I think I have stumbled upon a bug; if not then I apologize but I don't think this is by design?

using Mapster;

TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.Exact);
var e = new MyEntity
{
    Name = "Foo",
    Some_Value = "Bar"
};
var works = e.Adapt<MyDTO>();
var fails = e.Adapt<MyDTOWithConstructor>();

public record MyEntity
{
    public string Name { get; init; } = null!;
    public string Some_Value { get; init; } = null!;
}

public record MyDTO
{
    public string Name { get; init; }
    public string Some_Value { get; init; }
};


public record MyDTOWithConstructor
(
    string Name,
    string Some_Value
);

Mapping MyEntity to MyDTO works fine, as expected. However, when mapping to MyDTOWithConstructor the Some_Value property is not mapped. I have tried some other NameMatchingStrategy values but none seem to help. When I remove the underscore from the entity and DTO accordingly then everything works fine. I could also use explicit mappings. However, I have a LOT of entities and DTO's and I was hoping to keep it as simple as possible. I'm not sure if this behavior is by design but, at least, in my opinion, it doesn't seem very consistent?

Oh, using Mapster 7.2.0.

@andrerav
Copy link
Contributor

Fixed in #590

@Alberto-Armour
Copy link

Error still continue and not mapped _ properties i.e. Address_FirstName in 7.4.0 version.

@LeonardoDaLuz
Copy link

Error still continue and not mapped _ properties i.e. Address_FirstName in 7.4.0 version.

same here

@myalsailamy
Copy link

Error still continue and not mapped _ properties in 7.4.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants