AutoMapper.Extensions.ExpressionMapping 10.1.0

OData

AutoMapper extentions for mapping expressions (OData)

NuGet

To use, configure using the configuration helper method:

var mapper = new Mapper(new MapperConfiguration(cfg => {
    cfg.AddExpressionMapping();
	// Rest of your configuration
}, loggerFactory));

// or if using the MS Ext DI:

services.AddAutoMapper(cfg => {
    cfg.AddExpressionMapping();
}, /* assemblies with profiles */);

DTO Queries

Expression Mapping also supports writing queries against the mapped objects. Take the following source and destination types:

    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class Request
    {
        public int Id { get; set; }
        public int AssigneeId { get; set; }
        public User Assignee { get; set; }
    }

    public class UserDTO
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class RequestDTO
    {
        public int Id { get; set; }
        public UserDTO Assignee { get; set; }
    }

We can write LINQ expressions against the DTO collections.

ICollection<RequestDTO> requests = await context.Request.GetItemsAsync(mapper, r => r.Id > 0 && r.Id < 3, null, new List<Expression<Func<IQueryable<RequestDTO>, IIncludableQueryable<RequestDTO, object>>>>() { item => item.Include(s => s.Assignee) });
ICollection<UserDTO> users = await context.User.GetItemsAsync<UserDTO, User>(mapper, u => u.Id > 0 && u.Id < 4, q => q.OrderBy(u => u.Name));
int count = await context.Request.Query<RequestDTO, Request, int, int>(mapper, q => q.Count(r => r.Id > 1));

The methods below map the DTO query expresions to the equivalent data query expressions. The call to IMapper.Map converts the data query results back to the DTO (or model) object types.

    static class Extensions
    {
        internal static async Task<TModelResult> Query<TModel, TData, TModelResult, TDataResult>(this IQueryable<TData> query, IMapper mapper,
            Expression<Func<IQueryable<TModel>, TModelResult>> queryFunc) where TData : class
        {
            //Map the expressions
            Func<IQueryable<TData>, TDataResult> mappedQueryFunc = mapper.MapExpression<Expression<Func<IQueryable<TData>, TDataResult>>>(queryFunc).Compile();

            //execute the query
            return mapper.Map<TDataResult, TModelResult>(mappedQueryFunc(query));
        }

        internal static async Task<ICollection<TModel>> GetItemsAsync<TModel, TData>(this IQueryable<TData> query, IMapper mapper,
            Expression<Func<TModel, bool>> filter = null,
            Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryFunc = null,
            ICollection<Expression<Func<IQueryable<TModel>, IIncludableQueryable<TModel, object>>>> includeProperties = null)
        {
            //Map the expressions
            Expression<Func<TData, bool>> f = mapper.MapExpression<Expression<Func<TData, bool>>>(filter);
            Func<IQueryable<TData>, IQueryable<TData>> mappedQueryFunc = mapper.MapExpression<Expression<Func<IQueryable<TData>, IQueryable<TData>>>>(queryFunc)?.Compile();
            ICollection<Expression<Func<IQueryable<TData>, IIncludableQueryable<TData, object>>>> includes = mapper.MapIncludesList<Expression<Func<IQueryable<TData>, IIncludableQueryable<TData, object>>>>(includeProperties);

            if (f != null)
                query = query.Where(f);

            if (includes != null)
                query = includes.Select(i => i.Compile()).Aggregate(query, (list, next) => query = next(query));

            //Call the store
            ICollection<TData> result = mappedQueryFunc != null ? await mappedQueryFunc(query).ToListAsync() : await query.ToListAsync();

            //Map and return the data
            return mapper.Map<IEnumerable<TData>, IEnumerable<TModel>>(result).ToList();
        }
    }

Showing the top 20 packages that depend on AutoMapper.Extensions.ExpressionMapping.

Packages Downloads
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
9
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
8
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
7
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
6
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
5
AutoMapper.Collection.EntityFrameworkCore
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete.
3

Marking obsolete methods and classes.

.NET 8.0

.NET 9.0

.NET 10.0

.NET Standard 2.0

Version Downloads Last updated
10.1.0 1 21.02.2026
10.0.0 2 19.12.2025
9.0.1 4 05.08.2025
9.0.0 4 05.08.2025
8.0.0 7 19.03.2025
7.0.2 7 19.03.2025
7.0.1 7 19.03.2025
7.0.0 7 19.03.2025
6.0.4 6 19.03.2025
6.0.3 7 19.03.2025
6.0.2 7 19.03.2025
6.0.1 7 19.03.2025
6.0.0 7 19.03.2025
5.1.0 7 19.03.2025
5.0.3 7 19.03.2025
5.0.2 7 19.03.2025
5.0.1 7 19.03.2025
5.0.0 7 19.03.2025
4.1.5 6 19.03.2025
4.1.3 7 19.03.2025
4.1.2 7 19.03.2025
4.1.2-preview.0 6 19.03.2025
4.1.1 7 19.03.2025
4.1.1-preview.1 7 19.03.2025
4.1.1-preview.0 7 19.03.2025
4.1.0 7 19.03.2025
4.1.0-preview.0 7 19.03.2025
4.0.2 7 19.03.2025
4.0.2-preview-3 6 19.03.2025
4.0.2-preview-2 6 19.03.2025
4.0.1 7 19.03.2025
4.0.1-preview-4 6 19.03.2025
4.0.1-preview-3 6 19.03.2025
4.0.1-preview-2 6 19.03.2025
4.0.0 7 19.03.2025
4.0.0-preview01 6 19.03.2025
3.1.2 7 19.03.2025
3.1.2-preview01 6 19.03.2025
3.1.1 7 19.03.2025
3.1.1-preview01 7 19.03.2025
3.1.0 7 19.03.2025
3.1.0-preview02 6 19.03.2025
3.1.0-preview01 6 19.03.2025
3.0.6 7 19.03.2025
3.0.5 7 19.03.2025
3.0.4 7 19.03.2025
3.0.3 7 19.03.2025
3.0.2 7 19.03.2025
3.0.2-preview02 6 19.03.2025
3.0.1 7 19.03.2025
3.0.0 7 19.03.2025
2.0.2 7 19.03.2025
2.0.1 7 19.03.2025
2.0.0 7 19.03.2025
1.0.5 5 19.03.2025
1.0.4 7 19.03.2025
1.0.3 7 19.03.2025
1.0.2 7 19.03.2025
1.0.0 7 19.03.2025