AutoMapper.Extensions.ExpressionMapping 10.1.0

Prefix Reserved
dotnet add package AutoMapper.Extensions.ExpressionMapping --version 10.1.0
                    
NuGet\Install-Package AutoMapper.Extensions.ExpressionMapping -Version 10.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="10.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoMapper.Extensions.ExpressionMapping" Version="10.1.0" />
                    
Directory.Packages.props
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoMapper.Extensions.ExpressionMapping --version 10.1.0
                    
#r "nuget: AutoMapper.Extensions.ExpressionMapping, 10.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AutoMapper.Extensions.ExpressionMapping@10.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AutoMapper.Extensions.ExpressionMapping&version=10.1.0
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapper.Extensions.ExpressionMapping&version=10.1.0
                    
Install as a Cake Tool

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();
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (74)

Showing the top 5 NuGet packages that depend on AutoMapper.Extensions.ExpressionMapping:

Package 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.

AutoMapper.AspNetCore.OData.EFCore

Creates LINQ expressions from ODataQueryOptions and executes the query.

AutoMapper.Collection.EntityFramework

Collection updating support for EntityFramework 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.

Envoc.Core.Queries.Datatables

Package Description

Fluent.Architecture.Core

Package Description

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on AutoMapper.Extensions.ExpressionMapping:

Repository Stars
revoframework/Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
AutoMapper/AutoMapper.Collection
AutoMapper support for updating existing collections by equivalency
AutoMapper/AutoMapper.Collection.EFCore
EFCore support for AutoMapper.Collections
AutoMapper/AutoMapper.Extensions.OData
Creates LINQ expressions from ODataQueryOptions and executes the query.
Kation/ComBoost
ComBoost是一个领域驱动的快速开发框架
Version Downloads Last Updated
10.1.0 138 2/19/2026
10.0.0 21,340 12/10/2025
9.0.1 50,848 7/14/2025
9.0.0 28,264 7/12/2025
8.0.0 1,045,301 2/15/2025
7.0.2 1,612,891 9/16/2024
7.0.1 3,729,416 5/15/2024
7.0.0 2,693,070 2/7/2024
6.0.4 1,740,102 4/2/2023
6.0.3 292,569 1/27/2023
6.0.2 419,259 11/26/2022
6.0.1 162,843 10/30/2022
6.0.0 1,409,714 10/1/2022
5.1.0 682,785 6/28/2022
5.0.3 253,181 6/16/2022
5.0.2 263,643 4/8/2022
5.0.1 57,325 2/26/2022
5.0.0 734,606 1/5/2022
4.1.5 253,070 3/21/2022
4.1.3 288,444 10/23/2021
Loading failed

Marking obsolete methods and classes.