question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Projection with Automapper

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Wielebny666commented, 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)));
        }
    }
0reactions
coskuncinarcommented, Mar 4, 2019

@akinihsan do you have comments pls?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Projection
Projection transforms a source to a destination beyond flattening the object model. Without extra configuration, AutoMapper requires a flattened destination ...
Read more >
c# - Projection with Automapper
Check out the AutoMapper.EF6 project, it uses another project, DelegateDecompiler, to build out projections based on the method and property ...
Read more >
IncludeMembers and Custom Projections with AutoMapper
In this article, get ready to dive into custom projections with AutoMapper, using IncludeMembers and Value and Type Converters.
Read more >
Entity Framework Query Projection using Auto Mapper
AutoMapper is a library that transforms an object into another type. AutoMapper will copy property values with the same name and data type ......
Read more >
Simplify Your Projections with AutoMapper
The CreateMap call sets up a mapping between a source class and a destination class. AutoMapper has a number of built-in conventions to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found