automapperdev - AutoMapper.Collection 6.0.0-ci-00096

Collection Add/Remove/Update support for AutoMapper. AutoMapper.Collection adds EqualityComparison Expressions for TypeMaps to determine if Source and Destination type are equivalent to each other when mapping collections.

PM> Install-Package AutoMapper.Collection -Version 6.0.0-ci-00096 -Source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard

> nuget.exe install AutoMapper.Collection -Version 6.0.0-ci-00096 -Source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard

> dotnet add package AutoMapper.Collection --version 6.0.0-ci-00096 --source https://www.myget.org/F/automapperdev/api/v3/index.json

Copy to clipboard
<PackageReference Include="AutoMapper.Collection" Version="6.0.0-ci-00096" />
Copy to clipboard
source https://www.myget.org/F/automapperdev/api/v3/index.json

nuget AutoMapper.Collection  ~> 6.0.0-ci-00096
Copy to clipboard

> choco install AutoMapper.Collection --version 6.0.0-ci-00096 --source https://www.myget.org/F/automapperdev/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "automapperdev" -SourceLocation "https://www.myget.org/F/automapperdev/api/v2"
Install-Module -Name "AutoMapper.Collection" -RequiredVersion "6.0.0-ci-00096" -Repository "automapperdev" -AllowPreRelease
Copy to clipboard

AutoMapper

AutoMapper.Collection

Adds ability to map collections to existing collections without re-creating the collection object.

Will Add/Update/Delete items from a preexisting collection object based on user defined equivalency between the collection's generic item type from the source collection and the destination collection.

NuGet

How to add to AutoMapper?

Call AddCollectionMappers when configuring

Mapper.Initialize(cfg =>
{
    cfg.AddCollectionMappers();
    // Configuration code
});

Will add new IObjectMapper objects into the master mapping list.

Adding equivalency between two classes

Adding equivalence to objects is done with EqualityComparison extended from the IMappingExpression class.

cfg.CreateMap<OrderItemDTO, OrderItem>().EqualityComparison((odto, o) => odto.ID == o.ID);

Mapping OrderDTO back to Order will compare Order items list based on if their ID's match

Mapper.Map<List<OrderDTO>,List<Order>>(orderDtos, orders);

If ID's match, then AutoMapper will map OrderDTO to Order

If OrderDTO exists and Order doesn't, then AutoMapper will add a new Order mapped from OrderDTO to the collection

If Order exists and OrderDTO doesn't, then AutoMapper will remove Order from collection

Why update collection? Just recreate it

ORMs don't like setting the collection, so you need to add and remove from preexisting one.

This automates the process by just specifying what is equal to each other.

Can it just figure out the ID equivalency for me in Entity Framework?

Automapper.Collection.EntityFramework or Automapper.Collection.EntityFrameworkCore can do that for you.

Mapper.Initialize(cfg =>
{
    cfg.AddCollectionMappers();
// entity framework
    cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkPrimaryKeyPropertyMaps<DB>>();
// entity framework core
cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkCorePrimaryKeyPropertyMaps<DB>>();
    // Configuration code
});

User defined equality expressions will overwrite primary key expressions.

What about comparing to a single existing Entity for updating?

Automapper.Collection.EntityFramework does that as well through extension method from of DbSet

Translate equality between dto and EF object to an expression of just the EF using the dto's values as constants.

dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(newOrderDto);
dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(existingOrderDto);
dbContext.Orders.Persist().Remove<OrderDTO>(deletedOrderDto);
dbContext.SubmitChanges();

Note: This is done by converting the OrderDTO to Expression<Func<Order,bool>> and using that to find matching type in the database. You can also map objects to expressions as well.

Persist doesn't call submit changes automatically

Where can I get it?

First, install NuGet. Then, install AutoMapper.Collection from the package manager console:

PM> Install-Package AutoMapper.Collection

Additional packages

AutoMapper Collection for Entity Framework

PM> Install-Package AutoMapper.Collection.EntityFramework

AutoMapper Collection for Entity Framework Core

PM> Install-Package AutoMapper.Collection.EntityFrameworkCore

AutoMapper Collection for LinqToSQL

PM> Install-Package AutoMapper.Collection.LinqToSQL
  • .NETFramework 4.6.1
    • AutoMapper (>= 9.0.0)
  • .NETStandard 2.0
    • AutoMapper (>= 9.0.0)
  • .NETFramework 4.6.1: 4.6.1.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Jimmy Bogard

Authors

Tyler Carlson

Project URL

https://github.com/AutoMapper/Automapper.Collection

License

MIT

Info

1750 total downloads
7 downloads for version 6.0.0-ci-00096
Download (38.66 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
12.0.0 38.98 KB Fri, 07 Nov 2025 21:44:14 GMT 4
11.0.1-alpha.0.1 39.04 KB Fri, 07 Nov 2025 18:54:10 GMT 1
11.0.0 21.41 KB Sun, 16 Feb 2025 11:05:37 GMT 930
10.0.1-alpha.0.3 21.44 KB Sun, 16 Feb 2025 11:02:22 GMT 4
10.0.1-alpha.0.2 21.43 KB Sun, 16 Feb 2025 09:14:17 GMT 2
10.0.1-alpha.0.1 21.37 KB Thu, 11 Jul 2024 13:10:47 GMT 3
10.0.0 21.34 KB Mon, 12 Feb 2024 08:28:24 GMT 84
9.0.1-alpha.0.3 21.37 KB Mon, 12 Feb 2024 08:23:48 GMT 2
9.0.1-alpha.0.2 20.84 KB Sun, 15 Jan 2023 16:00:41 GMT 6
9.0.0 20.8 KB Wed, 05 Oct 2022 17:26:42 GMT 34
8.0.1-alpha.0.1 20.83 KB Tue, 04 Oct 2022 10:54:29 GMT 4
8.0.0 20.79 KB Thu, 31 Mar 2022 15:08:42 GMT 26
7.0.2-alpha.0.2 20.83 KB Thu, 31 Mar 2022 15:02:22 GMT 4
7.0.2-alpha.0.1 38.23 KB Fri, 12 Mar 2021 03:57:36 GMT 4
7.0.1 38.18 KB Mon, 23 Nov 2020 06:05:34 GMT 5
7.0.1-ci-00105 38.65 KB Sun, 15 Nov 2020 00:15:27 GMT 4
7.0.1-alpha.0.7 38.24 KB Mon, 23 Nov 2020 06:00:00 GMT 4
7.0.0 38.55 KB Sun, 05 Jul 2020 22:09:46 GMT 41
7.0.0-ci-00104 38.64 KB Sun, 15 Nov 2020 00:07:32 GMT 3
7.0.0-ci-00102 38.66 KB Sun, 05 Jul 2020 22:04:47 GMT 3
6.0.0 38.51 KB Wed, 25 Dec 2019 01:37:45 GMT 70
6.0.0-ci-00101 38.65 KB Sun, 05 Jul 2020 22:02:53 GMT 3
6.0.0-ci-00100 38.65 KB Sun, 05 Jul 2020 22:01:17 GMT 5
6.0.0-ci-00099 38.61 KB Wed, 25 Dec 2019 02:03:28 GMT 7
6.0.0-ci-00097 38.61 KB Wed, 25 Dec 2019 01:36:26 GMT 7
6.0.0-ci-00096 38.66 KB Tue, 22 Oct 2019 19:16:04 GMT 7
6.0.0-ci-00095 38.66 KB Thu, 15 Aug 2019 00:23:29 GMT 14
6.0.0-ci-00094 38.65 KB Thu, 15 Aug 2019 00:16:35 GMT 17
5.0.1-ci-00093 38.66 KB Mon, 03 Jun 2019 16:16:34 GMT 7
5.0.0 36.95 KB Tue, 20 Nov 2018 19:02:44 GMT 82
5.0.0-ci-00092 37.82 KB Mon, 06 May 2019 23:15:18 GMT 6
5.0.0-ci-00087 37.06 KB Sun, 18 Nov 2018 09:52:42 GMT 9
5.0.0-ci-00085 37.06 KB Sun, 18 Nov 2018 09:47:26 GMT 7
4.1.0-ci-00084 54.68 KB Thu, 23 Aug 2018 02:17:29 GMT 88
4.1.0-ci-00083 54.68 KB Thu, 26 Jul 2018 22:13:34 GMT 25
4.0.0 54.51 KB Thu, 26 Jul 2018 18:15:15 GMT 6
4.0.0-ci-00082 54.66 KB Thu, 26 Jul 2018 19:54:48 GMT 7
3.1.4 53.03 KB Wed, 27 Jun 2018 23:45:27 GMT 9
3.1.4-ci-00071 52.84 KB Wed, 06 Jun 2018 20:55:08 GMT 7
3.1.4-ci-00070 52.46 KB Wed, 16 May 2018 04:23:10 GMT 5
3.1.4-ci-00067 52.74 KB Fri, 29 Dec 2017 18:51:12 GMT 9
3.1.4-ci-00066 52.74 KB Wed, 27 Dec 2017 17:53:22 GMT 8
3.1.3 51.95 KB Mon, 27 Nov 2017 22:11:27 GMT 6
3.1.3-ci-00069 52.46 KB Tue, 15 May 2018 17:25:11 GMT 4
3.1.3-ci-00068 52.1 KB Fri, 09 Feb 2018 04:44:34 GMT 6
3.1.3-ci-00065 52.73 KB Tue, 26 Dec 2017 20:32:00 GMT 4
3.1.3-ci-00063 52.1 KB Mon, 27 Nov 2017 22:09:56 GMT 5
3.1.3-ci-00062 52.11 KB Mon, 27 Nov 2017 20:31:47 GMT 4
3.1.3-ci-00060 52.08 KB Wed, 09 Aug 2017 00:29:42 GMT 6
3.1.2 51.93 KB Tue, 08 Aug 2017 23:59:22 GMT 9
3.1.2-ci-00058 52.07 KB Tue, 08 Aug 2017 23:57:19 GMT 4
3.1.2-ci-00057 52.08 KB Wed, 12 Jul 2017 04:52:26 GMT 6
3.1.2-ci-00056 52.06 KB Fri, 07 Jul 2017 04:23:24 GMT 5
3.1.2-ci-00054 52.04 KB Fri, 07 Jul 2017 04:18:41 GMT 4
3.1.1 51.88 KB Fri, 07 Jul 2017 04:05:20 GMT 4
3.1.1-ci-00055 52.04 KB Fri, 07 Jul 2017 04:21:08 GMT 4
3.1.1-ci-00050 52.02 KB Fri, 07 Jul 2017 03:40:44 GMT 4
3.1.1-ci-00047 52.02 KB Tue, 04 Jul 2017 18:45:51 GMT 5
3.1.1-ci-00045 52.02 KB Tue, 04 Jul 2017 18:40:44 GMT 5
3.1.1-ci-00044 52.01 KB Tue, 04 Jul 2017 18:38:33 GMT 6
3.1.1-ci-00042 52.02 KB Tue, 04 Jul 2017 00:57:30 GMT 5
3.1.0-ci-00041 52.02 KB Tue, 04 Jul 2017 00:48:49 GMT 2
3.1.0-ci-00040 52 KB Tue, 04 Jul 2017 00:43:19 GMT 4
3.1.0-ci-00039 51.05 KB Fri, 30 Jun 2017 05:26:38 GMT 2
3.1.0-ci-00037 51.04 KB Fri, 30 Jun 2017 05:19:20 GMT 3
3.0.1 44.45 KB Thu, 25 May 2017 03:38:24 GMT 7
3.0.1-ci-00035 51.05 KB Fri, 30 Jun 2017 05:08:31 GMT 3
3.0.1-ci-00030 44.65 KB Thu, 25 May 2017 04:34:51 GMT 38
3.0.0-alpha-00013 40.39 KB Thu, 16 Mar 2017 16:23:33 GMT 5
3.0.0-alpha-00012 40.4 KB Thu, 26 Jan 2017 05:51:30 GMT 7
3.0.0-alpha-00011 40.41 KB Fri, 20 Jan 2017 07:24:51 GMT 4
3.0.0-alpha-00010 39.61 KB Fri, 20 Jan 2017 06:56:30 GMT 3
3.0.0-alpha-00009 39.61 KB Thu, 19 Jan 2017 07:24:14 GMT 3