-
Notifications
You must be signed in to change notification settings - Fork 326
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
Proposal - Mapster 3.0 #38
Comments
+1 |
What do you think about this feature:
it's possible now with double adapt like this:
but chain syntax guarantees that these two lines wont be split from eachother during refactorings and looks neat and I'm not sure how to add "strategy" with an existin Or maybe you can advice how can I implement this as extension methods with strategy as a dynamic parameter ? |
how about create extension methods
now you could do something like
NOTE: with this method last one will win. If you need first one win, you might need to create a builder class. |
@centur, sorry, I don't understand your comment. |
Well, me neither now, Friday was a hard day :(... I deleted it. I think the idea I had in mind was something like this: Trying to understand if it'd be good (and it may be a bad idea, and it's ok ) or possible to have something like composable set of rules where user can define mapping behaviour in runtime. Gettting back to our example:
As a result of such rules application - in this particular mapping I suspect that this may be impossible because Mapster is creating and caching compiled versions of end-result functions that are used for actual mapping (is this right ?) |
This is the idea of inline mapping. It is # 4 in list above. I have idea of implementation, We can cache the compilation even it is specified inline. But I have no time to implement it. For now, my suggestion is to clone config and cache it somewhere. For example:
With above configuration, Cache could be global field of |
Hi. About task no. 10. Is anybody thinking how would it be from user perspective? Or maybe even implementing it? This feature is interesting for us as well. I cannot promise anything, but I could at least look at in my free time and try to do something. But it would be fine to have some "specification" - requirements what we expect and also how could it be configured etc. Maybe we can create separate issue for that and discuss things there? |
Hi @satano, It would be great if you can help implement this feature. I'm bad in writing specification, but I will try. If we have domain class
And we map with To configure, here (link), To create MapToTarget expression, we can copy & adapt from here (link). Method name in linq should be Hope this help :) |
@chaowlert is the |
I put this to dump my idea here and for discussion to implement new features.
1. Setting per hierarchy
Currently, Mapster can setup only per type pair. Suppose we have
Student
andSchool
and those types are related each other, we need to create 2 configs for each type. The idea is we should be able to create only one config.Suppose we create this setting:
The setting should apply to both
Student
mapping andSchool
mapping. Anyway, if we callTypeAdapter.Adapt<School, SchoolDTO>()
above setting should not be applies.To make V3.0 compatible with V2.0, we could use global setting:
Above setting will apply setting per type rather than setting per hierarchy.
2. IgnoreAll & IgnoreNavigationProperties & Include
Now we have
Ignore
to opt-out properties we wouldn't like to map. The idea is to have opt-in mapping properties.IgnoreAll
will ignore all properties.IgnoreNavigationProperties
will ignore all properties except primitives. AndInclude
will include properties in mapping even that properties are ignored. This should be useful for projection where normally EF will exclude navigation properties by default and we need to call include to add properties in. We can do following setting.This
IgnoreNavigationProperties
&Include
setting will also solve #34.3. Navigation path
The idea is from #35.
Map
,Ignore
, andInclude
method should accept navigation path, both string and expression. For example:4. Inline setting
Currently, we need to separate between config and Adapt method. In some scenario, we might would like to maintain config and Adapt method together. For example:
Inline setting should apply global setting but it should not alter global setting. We can cache setting and compile result using caller information.
For projection, usage might be slightly different.
5. Rename projection method(Done #40)This should has high impact to everyone who use projection. But in VB, currentTo
method is not fluent.Dim result = context.Students.Project().To(Of StudentDTO)()
I thinkTo
method should be changed toToType
method.Dim result = context.Students.Project().ToType(Of StudentDTO)()
var result = context.Students.Project().ToType<StudentDTO>();
I haven't prefer VB but I thinkTo
method naming is not correct per .NET convention. Another option is to have an alias, but I proposed to rename as it will be less confused.6. Name mapping strategy(Done #57)This is for resolving property name. In some cases, we might would like to match proper case to camel case (src.HelloWorld
todest.helloWorld
) without manual mapping.7. Passing run-time value(Done #55)This is for Mapster to allow passing run-time value ie.this.User.Identity.Name
to mapping context.8. Object to Dictionary & Dictionary to Object(Done #56)This is to allow conversion between Object and Dictionary.9. Support dynamic
To convert from/to dynamic.
10. Preserve destination object
Currently when Mapster copy properties from source to destination object, Mapster will create new object for properties. In EF, if we create new navigation objects, EF will create new records. Mapster should preserve object, so when users copy entire object graph, EF will not create new records.
11. Match item when copy list
Continue from 10, when we copy list, Mapster will add new objects to list. EF will create new records for each item. Mapster should be able to identify objects from key and copy to that object.
The text was updated successfully, but these errors were encountered: