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

Properties that contain capitalized abbreviations cannot also be mapped in the fluent API when mapping to a record #370

Closed
CerebralUnit opened this issue Sep 3, 2021 · 6 comments
Assignees

Comments

@CerebralUnit
Copy link

There are several properties in the Adverse record on the domain model that have abbreviations and are therefore capitalized (e.g. HDMAReasons.) Regardless of the naming strategy Exact, IgnoreCase, Flexible etc.. Mapster will fail execute a custom mapping unless a Pascal case version of the property is passed in for the destination object. Using x => x.HDMAReasons causes the mapper to throw a configuration error saying that there is neither a mapping nor an Ignore for HdmaReasons. Neither object being mapped has that casing. Example of the code that finally worked below.

config.MapDependentTo<Adverse, Domain.Adverse>()
.MapToConstructor(true)
.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase)
.Map("HmdaReasons", src => src.HMDAReasons.Select(x => x.EnumValue))

@andrerav
Copy link
Contributor

Might be related to #388.

@JMPSequeira
Copy link

@CerebralUnit could you provide the models used for the issue? And please clarify if the specific problem only occurs when mapping to a constructor.

@andrerav andrerav self-assigned this Jan 7, 2023
@ventii
Copy link

ventii commented Mar 7, 2023

Had the exact same issue - fields with consecutive capital letters in a C# record constructor are not mapped even when the source record/class has the same field with the same name.

non working example:

public record MySourceRecord(DateTime ValidFromUTC);

public record MyDestinationRecord(DateTime ValidFromUTC);

// having the following config
config.NewConfig<MySourceRecord, MyDestinationRecord>();

got it to work by doing the following changes:

// change property name of destination record to PascalCase
public record MyDestinationRecord(DateTime ValidFromUtc);

// update config to specify mapping

config.NewConfig<MySourceRecord, MyDestinationRecord>()
                .Map(dest => dest.ValidFromUtc, src => src.ValidFromUTC);

I was going crazy as I initially thought it was some bug with DateTime.

Is this a known issue please?

@andrerav
Copy link
Contributor

andrerav commented Mar 7, 2023

@ventii Yes this is a known issue, the name matching strategy does not seem to be working as intended.

@andrerav
Copy link
Contributor

andrerav commented Mar 7, 2023

See also #388.

joshslark pushed a commit to joshslark/Mapster that referenced this issue May 21, 2023
joshslark pushed a commit to joshslark/Mapster that referenced this issue May 21, 2023
joshslark added a commit to joshslark/Mapster that referenced this issue May 21, 2023
joshslark added a commit to joshslark/Mapster that referenced this issue May 21, 2023
andrerav added a commit that referenced this issue May 29, 2023
Fix #370 where capitalized abbreviations are not mapped …
@leseneda
Copy link

leseneda commented Jul 2, 2024

I solved my issue using the following code line;

globalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.Flexible);

Mapster 7.4.0

Hope this helps.

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

No branches or pull requests

5 participants