Skip to content
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

Mapper.Map not working withing CreateMap #1587

Closed
Zhobday opened this issue Aug 3, 2016 · 10 comments
Closed

Mapper.Map not working withing CreateMap #1587

Zhobday opened this issue Aug 3, 2016 · 10 comments

Comments

@Zhobday
Copy link

Zhobday commented Aug 3, 2016

config.CreateMap<StatuteDocument, StatuteViewModel>()
                    .ForMember(x => x.Title, y => y.MapFrom(x => x.OriginalTitle))
                    .ForMember(x => x.HasFullText, y => y.MapFrom(x => x.FulltextStatus == FulltextStatus.Available))
                    .ForMember(x => x.FullText,
                        y => y.MapFrom(x => (x == null || !x.XmlDoc.Any()) ? string.Empty : x.XmlDoc[0].XmlDoc))
                    .ForMember(x => x.ParallelCitations,
                        y => y.MapFrom(src => new List<CitationViewModel> { Mapper.Map<CitationViewModel>(src.Citation) }));

The last .ForMember for ParallelCitations causes issues in the code when i call the Map within the API, the map Citation to CitationViewModel was created earlier in the config, Anybody know how to refactor this for V.5. thanks.

@lbargaoanu
Copy link
Member

Just remove Mapper.Map.

@Zhobday
Copy link
Author

Zhobday commented Aug 3, 2016

For some reason the code has changed in the preview section it actually looks like this,

ForMember(x => x.ParallelCitations,
                        y => y.MapFrom(src => new List<CitationViewModel> { Mapper.Map<CitationViewModel>(src.Citation) }));

@Zhobday Zhobday closed this as completed Aug 3, 2016
@Zhobday Zhobday reopened this Aug 3, 2016
@Zhobday
Copy link
Author

Zhobday commented Aug 3, 2016

The remove mapper.map doesnt work as the src.Citation value is not the same type as the Parallel citations

@lbargaoanu
Copy link
Member

Make a gist that shows it doesn't work.

@jbogard
Copy link
Member

jbogard commented Aug 4, 2016

Can you post your models? It looks like you're trying to map a single property in the source model into a list in the destination model, is that right?

@Zhobday
Copy link
Author

Zhobday commented Aug 4, 2016

That is right yes, the models are basic and they were working in the 4.2 version but in this new update the error given complains about the ParralelCitations property.

@jbogard
Copy link
Member

jbogard commented Aug 4, 2016

Ok, for using Mapper.Map, you need to use ResolveUsing and the overload that takes the resolution context. On that one is a mapper object that you'd use, not back to a static reference.

@lbargaoanu
Copy link
Member

@jbogard But why do that? Just MapFrom the source expression would work.

@lbargaoanu
Copy link
Member

This can be closed.

@Zhobday Zhobday closed this as completed Aug 24, 2016
@lock
Copy link

lock bot commented May 7, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants