AutoMapperMIT.Collection
14.0.1
dotnet add package AutoMapperMIT.Collection --version 14.0.1
NuGet\Install-Package AutoMapperMIT.Collection -Version 14.0.1
<PackageReference Include="AutoMapperMIT.Collection" Version="14.0.1" />
<PackageVersion Include="AutoMapperMIT.Collection" Version="14.0.1" />
<PackageReference Include="AutoMapperMIT.Collection" />
paket add AutoMapperMIT.Collection --version 14.0.1
#r "nuget: AutoMapperMIT.Collection, 14.0.1"
#:package AutoMapperMIT.Collection@14.0.1
#addin nuget:?package=AutoMapperMIT.Collection&version=14.0.1
#tool nuget:?package=AutoMapperMIT.Collection&version=14.0.1
<img src="https://s3.amazonaws.com/automapper/logo.png" alt="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.
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<TEntity>.
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 AutoMapperMIT.Collection from the package manager console:
PM> Install-Package AutoMapperMIT.Collection
Additional packages
AutoMapper Collection for Entity Framework
PM> Install-Package AutoMapperMIT.Collection.EntityFramework
AutoMapper Collection for Entity Framework Core
PM> Install-Package AutoMapperMIT.Collection.EntityFrameworkCore
AutoMapper Collection for LinqToSQL
PM> Install-Package AutoMapperMIT.Collection.LinqToSQL
| Product | Versions 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 was computed. 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 was computed. 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 was computed. 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. |
-
.NETStandard 2.0
- AutoMapperMIT (>= 14.0.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AutoMapperMIT.Collection:
| Package | Downloads |
|---|---|
|
AutoMapperMIT.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. |
|
|
AutoMapperMIT.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. |
|
|
AutoMapperMIT.Collection.LinqToSQL
Collection updating support for LinqToSQL with AutoMapper. Extends Table<T> with Persist<TDto>().InsertUpdate(dto) and Persist<TDto>().Delete(dto). Will find the matching object and will Insert/Update/Delete. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 14.0.1 | 2,014 | 3/18/2026 |