Skip to main content

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.

Total Downloads
20.3K
20,275
Published
May 14, 2026
5mo ago

Get Started

dotnet add package AutoMapperMIT.Collection.EntityFrameworkCore --version 14.0.3
ProductVersions
.NET
net6.0

README

AutoMapper.Collection.EntityFrameworkCore

Automapper.Collection.EntityFrameworkCore will help you when mapping an EntityFramework Core DbContext-object.

NuGet

Configuration examples

  • Usage together with Dependency injection and AutoMapper.Extensions.Microsoft.DependencyInjection package
var services = new ServiceCollection();
services
    .AddEntityFrameworkInMemoryDatabase()
    .AddDbContext<DB>();

services.AddAutoMapper((serviceProvider, automapper) =>
{
    automapper.AddCollectionMappers();
    automapper.UseEntityFrameworkCoreModel<DB>(serviceProvider);
}, typeof(DB).Assembly);

var serviceProvider = services.BuildServiceProvider();

Note: User defined equality expressions will overwrite primary key expressions.

What about comparing to a single existing Entity for updating?

Automapper.Collection.EntityFrameworkCore 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(mapper).InsertOrUpdate<OrderDTO>(newOrderDto);
	dbContext.Orders.Persist(mapper).InsertOrUpdate<OrderDTO>(existingOrderDto);
	dbContext.Orders.Persist(mapper).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

How to get it

Use NuGet Package Manager to install the package or use any of the following commands in NuGet Package Manager Console.

PM> Install-Package AutoMapperMIT.Collection.EntityFrameworkCore

Downloads by Version

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.