-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Mapping and Projecting enum strange behavior #840
Comments
Well, to use projection, the LINQ provider needs to understand that ProjectUsing piece. The trick is to find the correct expression that EF I'm assuming will understand. What behavior are you seeing? |
The behavior I didn't except is based on 2 points:
And both mappings work: To just project, as I said in 1., I can configure it like this:
And both projections work: The problem happens when I wanna map and project, because the configuration above doesn't work, so I need to configure it differently:
In other words, I don't need to create enum mapping, but if I create it (to project, for instance), I also need to call another method (.ConvertUsing(...)) to tell AutoMapper how to map enum. The gist I created has unit tests of the 3 use cases above. I believe that if it is the expected behavior, it should be explained in documentation at least. I searched on, but I found nothing about enum specifically. So I spent some time trying different configurations to find a working one :( hahaha |
AutoMapper has two modes, projection and mapping. Projection uses only Hence the difference. If you want to map and project with low level mappings, you need to use On Wednesday, August 19, 2015, Breno Vieira notifications@github.com
|
@jbogard, I'm sorry for the delay.
That's absolutelly correct.
That I'm not sure. I didn't dig into this part of the AutoMapper code, but as an AutoMapper user perspective I see that:
What I'm suggesting is AutoMapper creates the expression tree to enum-enum projections. In my large AutoMapper config, I just call .ProjectUsing() and .ConvertUsing() with enums. I map and project two POCO classes (with same property names), just callling On the other hand, to enum I don't need to call CreateMap<> to use mapping. It's not a clear behavior to me and the documentation doesn't explain that. |
Yeah, in fact MapFrom does work on both sides which kinda invalidated my argument. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It's quite a question father than an issue, because I don't know the right behavior. I'm using AutoMapper 4.0.4.
I'm trying to map and project (ProjectTo<>) some enum properties and the only working configuration I found was something like:
Mapper.Initialize(cfg => ...)
orMapper.AddProfile<Profile>()
have the same behaviorIs there another way (simpler) to achieve that (mapping and projecting enums)?
I'm asking this because I have several enums and if I just map them, there is no need of creating enum mapping, but projecting them doesn't work "automatically".
Please see a gist I created here: https://gist.github.com/brenovieira/106b904f3899713e090d
The text was updated successfully, but these errors were encountered: