-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Feature Description
Currently, Linqraft generates conversion methods from Entities to DTOs, but does not generate reverse conversion methods.
This is due to the design consideration that "reverse conversion" can be complex in certain scenarios (e.g., when functions like Select, Count, FirstOrDefault are used internally).
However, in many common cases, reverse conversion is useful (as supported by many mapping libraries). Therefore, we propose providing an option to generate reverse conversion methods for simple cases.
Triggering Example
// A pattern where a separate factory class is provided and attributes are applied there could also be effective.
query.SelectExpr<Entity,EntityDto>(x => new { ... });
[LinqraftReverseConvertion<EntityDto>(IsStatic = true)]
public partial class EntityDtoReverseConverter;
// generated
public partial class EntityDtoReverseConverter
{
public static Entity FromDto(EntityDto){ ... }
public static IEnumerable<Entity> FromDtoProjection(IEnumerable<EntityDto>){ ... }
}Generated Expected Output
Natural "reverse conversion" methods. Generate ToEntity methods for both EntityDto and IEnumerable<EntityDto>.
Additional Information
Whether reverse transformation is possible can be determined based on the following criteria. Using a whitelist-based transformation approach is simple.
- Simple property access (
Item = x.Foo.Bar.Buz): Reverse transformation is possible. You simply perform the reverse operation (e.g.,x.Foo.Bar.Buz = Item). Select/SelectMany/SelectExpraccess: Reverse transformation is possible. You perform the reverse selection operation based on the original data structure.Where/First/Last/FirstOrDefaultfiltering: Reverse transformation is possible. You simply ignore it and behave as if there is noWhere. The data after reverse transformation will be in a "missing" state.ToList/ToArray, etc.: Reverse transformation is possible. You simply ignore it and behave as if it were anIEnumerable.- Aggregation operations (
Count,Sum,Average, etc.): Reverse transformation is not possible. The transformation itself is not performed.