Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Feature request: also force all source properties to be in destination

Open suntereo opened this issue 2 years ago • 1 comments

Thanks for a great and useful package!

We are using RequireDestinationMemberSource and it works well:

  • RequireDestinationMemberSource: "Forcing all destination properties to have a corresponding source member or explicit mapping/ignore" (source)

But we also have a need to check the other direction. Is there any plans or would it be possible to introduce a new property:

  • RequireSourceMemberDestination: Force all source properties to have a corresponding destination member

One scenario is where there's a one-way mapping from a stored proc DAO to DTO. A field is added to the table, picked up and added to the DAO by the EF Core PowerTools Reverse Engineering Tool, but not added to the DTO because the programmer forgot. We would love to see it throw an error here to alert us that the new property need to also be added to the DTO (destination) because it's in the source (DAO).

Another scenario is where a property is added to a request for a Save() web method. It was added to the SL but the programmer fails to add it to the DTO (and DAO). It might appear as though this new property is being saved from the front-end. But it isn't because it's just ignored. We would love to see an error thrown here to alert us that it's not being passed down.

p.s. The property names always confuse me. Wouldn't this be better:

  • EveryDestinationPropertyMustBeInSource (existing property)
  • EverySourcePropertyMustBeInDestination (new property) Or even:
  • RequireAllDestinationPropertiesToBeInSource (existing property)
  • RequireAllSourcePropertiesToBeInDestination (new property)

suntereo avatar Feb 22 '23 22:02 suntereo

+1, AutoMapper implements this as MemberList.Source: https://docs.automapper.io/en/stable/Configuration-validation.html.

mariusz96 avatar Jul 08 '25 09:07 mariusz96