'Automapper - projectTo() - Aggregation on base entity (DbSet)
I'm trying to aggregate multiple filters against my base entity when using the projectTo() method.
However if I define a IQueryable<TSource> to <TDestination> profile, automapper is always trying to map between <TSource> and <TDestination>. And so the mapping profile is not found.
I see in the docs it is possible to aggregate against a member list.
Is this possible with Automapper?
DbEntity (Source)
public SomeClass {
Member1: bool
Member2: bool
}
Destination
public DestinationClass {
TotalSomeClass: int;
TotalSomeClassWithMember1True: int;
}
Mapping Profile (Not working)
CreateMap<IQueryable<SomeClass>, DestinationClass >()
.ForMember(d => d.TotalSomeClass, o
=> o.MapFrom(s => s.Count()))
.ForMember(d => d.TotalSomeClassWithMember1True, o
=> o.MapFrom(s => s.Count(s => s.Member1 == true)))
Usage (Automapper 11 with dependency injection)
var result = _mapper.ProjectTo<DestinationClass>(_context.SomeClass);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
