You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And we would like to create a simple mapping from User to UserDto. As often we will use a lot of properties with the same name in the entity and the dto. For now, the solution is:
createMap(mapper,User,UserDto,forMember(d=>d.name,mapFrom(s=>s.name)),forMember(d=>d.email,mapFrom(s=>s.email)),forMember(d=>d.id,mapFrom(s=>s.id)),// As you can see, the password is not mapped);
Mapping properties between classes, such as User and UserDto, in JavaScript is currently a manual and tedious process. It involves repetitive work, especially when dealing with numerous properties, and can become challenging when new properties are added. Unlike AutoMapper in C#, which automatically maps properties with the same names, JavaScript lacks this capability due to the inability to extract property names from classes.
The primary problem is to simplify and automate property mapping in JavaScript, similar to AutoMapper in C#, by automatically mapping properties with matching names unless explicitly ignored.
Solution
To streamline the configuration and enable the automatic mapping of properties with matching names, I suggest the implementation of shortcut functions. These functions serve as efficient ways to configure the mapping process manually.
createMap(mapper,User,UserDto,copyManyProperties('id','name','email'),// As you can see, the password is not mapped);
This approach offers a more concise and manageable method for mapping properties. Although achieving automatic mapping identical to AutoMapper in C# may not be feasible in JavaScript due to the inability to extract property names from classes, these functions significantly enhance the mapping process and reduce repetitive tasks.
By employing this technique, developers have the flexibility to add properties as a list. This list can be created either manually or by utilizing a proxy object to retrieve the property names.
Here's a basic example of code for the copySingleProperty function:
Furthermore, consider making utility functions available for developers to simplify the creation of their custom configurations. These utilities, such as getMember, getMemberPath, and others, can facilitate the process of defining individualized mapping configurations.
Describe alternatives you've considered
No response
Additional context
Dependencies:
@automapper/classes (Version 8.7.7)
@automapper/core (Version 8.7.7)
typescript (Version 5.2.2)
tsc (Version 2.0.4)
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
Problem
Let's assume we have the following classes:
And we would like to create a simple mapping from User to UserDto. As often we will use a lot of properties with the same name in the entity and the dto. For now, the solution is:
Mapping properties between classes, such as User and UserDto, in JavaScript is currently a manual and tedious process. It involves repetitive work, especially when dealing with numerous properties, and can become challenging when new properties are added. Unlike AutoMapper in C#, which automatically maps properties with the same names, JavaScript lacks this capability due to the inability to extract property names from classes.
The primary problem is to simplify and automate property mapping in JavaScript, similar to AutoMapper in C#, by automatically mapping properties with matching names unless explicitly ignored.
Solution
To streamline the configuration and enable the automatic mapping of properties with matching names, I suggest the implementation of shortcut functions. These functions serve as efficient ways to configure the mapping process manually.
copySingleProperty function:
copyManyProperties function:
This approach offers a more concise and manageable method for mapping properties. Although achieving automatic mapping identical to AutoMapper in C# may not be feasible in JavaScript due to the inability to extract property names from classes, these functions significantly enhance the mapping process and reduce repetitive tasks.
By employing this technique, developers have the flexibility to add properties as a list. This list can be created either manually or by utilizing a proxy object to retrieve the property names.
Here's a basic example of code for the copySingleProperty function:
Furthermore, consider making utility functions available for developers to simplify the creation of their custom configurations. These utilities, such as getMember, getMemberPath, and others, can facilitate the process of defining individualized mapping configurations.
Describe alternatives you've considered
No response
Additional context
Dependencies:
@automapper/classes
(Version 8.7.7)@automapper/core
(Version 8.7.7)typescript
(Version 5.2.2)tsc
(Version 2.0.4)The text was updated successfully, but these errors were encountered: