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

Projection with Automapper #46

Closed
attiqeurrehman opened this issue Oct 28, 2017 · 8 comments
Closed

Projection with Automapper #46

attiqeurrehman opened this issue Oct 28, 2017 · 8 comments

Comments

@attiqeurrehman
Copy link

Hi,

I was previously using the following LINQ query for a generic page list with automapper for all my entities:

var projection = queryable.OrderByPropertyOrField(orderBy, ascending).Skip(skipAmount).Take(pageSize).ProjectTo<TReturn>(Mapper.ConfigurationProvider);

Can I use the automapper projection with GetPagedList?

@rigofunc
Copy link
Member

Maybe, let me try later

@Wielebny666
Copy link

Wielebny666 commented Oct 29, 2017

Hi,
map config:

 CreateMap<Model, ViewModel>()
.ForMember(dest => dest.property, opt => opt.MapFrom(src => src.property));

CreateMap<IPagedList<Model>, IPagedList<ViewModel>>()
.ConvertUsing<PagedListToPagedListConverter<Model, ViewModel>>();

converter class:

public class PagedListToPagedListConverter<T1, T2> : ITypeConverter<IPagedList<T1>, IPagedList<T2>>
    {
        public IPagedList<T2> Convert(
            IPagedList<T1> source,
            IPagedList<T2> destination,
            ResolutionContext context)
        {
            var models = source as PagedList<T1>;
            return PagedList.From(models, c => new List<T2>(Mapper.Map<IEnumerable<T2>>(c)));
        }
    }

@Wielebny666
Copy link

Helped You?

@rigofunc
Copy link
Member

rigofunc commented Nov 5, 2017

Good start, thanks

@attiqeurrehman
Copy link
Author

Sorry for late reply, I went with GetAll method to get IQueryable and projected it with automapper.

-A

@georgepaoli
Copy link

Thank you @Wielebny666 !!!

@coskuncinar
Copy link

Hello @Wielebny666

I am using this framework
And i dont know how to use the PagedListToPagedListConverter in GetPagedListAsync

Can you open this topic a little more?
Its important subject.
Please help me

@coskuncinar
Copy link

@akinihsan
do you have comments pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants