automapperdev - AutoMapper.Collection.EntityFrameworkCore 10.0.0
Collection updating support for EntityFrameworkCore with AutoMapper. Extends DBSet
PM> Install-Package AutoMapper.Collection.EntityFrameworkCore -Version 10.0.0 -Source https://www.myget.org/F/automapperdev/api/v3/index.json
> nuget.exe install AutoMapper.Collection.EntityFrameworkCore -Version 10.0.0 -Source https://www.myget.org/F/automapperdev/api/v3/index.json
> dotnet add package AutoMapper.Collection.EntityFrameworkCore --version 10.0.0 --source https://www.myget.org/F/automapperdev/api/v3/index.json
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="10.0.0" />
Copy to clipboard
source https://www.myget.org/F/automapperdev/api/v3/index.json
nuget AutoMapper.Collection.EntityFrameworkCore ~> 10.0.0
Copy to clipboard
> choco install AutoMapper.Collection.EntityFrameworkCore --version 10.0.0 --source https://www.myget.org/F/automapperdev/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "automapperdev" -SourceLocation "https://www.myget.org/F/automapperdev/api/v2"
Install-Module -Name "AutoMapper.Collection.EntityFrameworkCore" -RequiredVersion "10.0.0" -Repository "automapperdev"
Copy to clipboard
Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/automapperdev/api/v2/symbolpackage/
AutoMapper.Collection.EntityFrameworkCore
Automapper.Collection.EntityFrameworkCore
will help you when mapping an EntityFramework Core DbContext-object.
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 AutoMapper.Collection.EntityFrameworkCore
-
.NETFramework 6.0
- AutoMapper.Collection (>= 10.0.0 && < 11.0.0)
- AutoMapper.Extensions.ExpressionMapping (>= 7.0.0 && < 8.0.0)
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- .NETFramework 6.0: 6.0.0.0
OwnersJimmy Bogard |
AuthorsTyler Carlson |
Project URLhttps://github.com/AutoMapper/Automapper.Collection.EFCore |
LicenseMIT |
Info143 total downloads |
1 downloads for version 10.0.0 |
Download (10.2 KB) |
Download symbols (9.6 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
10.0.0 | 10.2 KB | Thu, 15 Feb 2024 14:40:41 GMT | 1 | ||||
9.0.1-alpha.0.1 | 10.24 KB | Thu, 15 Feb 2024 14:38:20 GMT | 0 | ||||
9.0.0 | 16.48 KB | Thu, 13 Oct 2022 16:20:05 GMT | 2 | ||||
8.0.1-alpha.0.2 | 16.54 KB | Thu, 13 Oct 2022 13:58:17 GMT | 1 | ||||
8.0.1-alpha.0.1 | 16.53 KB | Thu, 13 Oct 2022 13:28:08 GMT | 1 | ||||
8.0.0 | 16.62 KB | Fri, 01 Apr 2022 13:39:49 GMT | 1 | ||||
7.1.4-alpha.0.1 | 16.69 KB | Fri, 01 Apr 2022 13:30:59 GMT | 1 | ||||
7.1.3 | 29.76 KB | Tue, 30 Nov 2021 02:54:27 GMT | 2 | ||||
7.1.3-alpha.0.1 | 29.91 KB | Tue, 30 Nov 2021 02:55:10 GMT | 1 | ||||
7.1.2-alpha.0.1 | 29.9 KB | Tue, 30 Nov 2021 02:44:41 GMT | 1 | ||||
7.1.1-alpha.0.1 | 29.88 KB | Sun, 28 Nov 2021 23:10:50 GMT | 1 | ||||
7.0.2-alpha.0.2 | 29.88 KB | Sat, 02 Oct 2021 01:19:52 GMT | 2 | ||||
7.0.2-alpha.0.1 | 16.92 KB | Wed, 23 Dec 2020 18:37:43 GMT | 2 | ||||
7.0.1 | 16.86 KB | Mon, 23 Nov 2020 08:14:40 GMT | 2 | ||||
7.0.1-alpha.0.1 | 16.92 KB | Mon, 23 Nov 2020 08:13:42 GMT | 1 | ||||
7.0.0 | 15.61 KB | Sun, 15 Nov 2020 19:02:35 GMT | 1 | ||||
7.0.0-ci-00029 | 15.71 KB | Sun, 15 Nov 2020 19:00:44 GMT | 1 | ||||
1.0.1 | 15.6 KB | Tue, 22 Oct 2019 19:24:15 GMT | 3 | ||||
1.0.1-ci-00028 | 15.67 KB | Wed, 16 Sep 2020 01:33:13 GMT | 1 | ||||
1.0.1-ci-00027 | 15.66 KB | Wed, 26 Aug 2020 21:52:59 GMT | 1 | ||||
1.0.1-ci-00026 | 15.64 KB | Mon, 24 Aug 2020 16:51:40 GMT | 1 | ||||
1.0.1-ci-00025 | 15.76 KB | Sat, 23 Nov 2019 19:08:37 GMT | 3 | ||||
1.0.1-ci-00023 | 15.71 KB | Tue, 22 Oct 2019 19:23:18 GMT | 2 | ||||
1.0.1-ci-00022 | 15.7 KB | Tue, 22 Oct 2019 19:19:36 GMT | 2 | ||||
1.0.0 | 15.59 KB | Sun, 20 Oct 2019 15:50:03 GMT | 2 | ||||
1.0.0-ci-00020 | 15.71 KB | Sun, 20 Oct 2019 15:45:16 GMT | 2 | ||||
1.0.0-ci-00019 | 15.71 KB | Sun, 20 Oct 2019 15:22:15 GMT | 2 | ||||
1.0.0-ci-00018 | 15.72 KB | Sun, 20 Oct 2019 15:13:40 GMT | 2 | ||||
0.3.0-ci-00017 | 15.68 KB | Thu, 15 Aug 2019 00:36:11 GMT | 2 | ||||
0.3.0-ci-00016 | 15.68 KB | Thu, 15 Aug 2019 00:35:07 GMT | 2 | ||||
0.3.0-ci-00015 | 15.68 KB | Thu, 25 Jul 2019 23:40:12 GMT | 2 | ||||
0.3.0-ci-00013 | 15.68 KB | Tue, 26 Mar 2019 14:59:04 GMT | 2 | ||||
0.3.0-ci-00012 | 12.44 KB | Tue, 26 Mar 2019 14:57:16 GMT | 2 | ||||
0.2.0 | 12.34 KB | Wed, 20 Mar 2019 02:31:33 GMT | 2 | ||||
0.2.0-ci-00010 | 12.43 KB | Wed, 20 Mar 2019 02:29:35 GMT | 2 | ||||
0.1.0 | 12.07 KB | Wed, 21 Nov 2018 14:42:13 GMT | 2 | ||||
0.1.0-ci-00014 | 12.19 KB | Mon, 29 Apr 2019 20:24:32 GMT | 2 | ||||
0.1.0-ci-00009 | 12.41 KB | Wed, 13 Feb 2019 15:28:12 GMT | 2 | ||||
0.1.0-ci-00008 | 12.17 KB | Sun, 25 Nov 2018 16:39:56 GMT | 2 | ||||
0.1.0-ci-00006 | 12.17 KB | Wed, 21 Nov 2018 14:40:39 GMT | 2 | ||||
0.1.0-ci-00005 | 12.17 KB | Tue, 20 Nov 2018 22:19:08 GMT | 2 | ||||
0.1.0-ci-00004 | 12.23 KB | Sun, 16 Sep 2018 23:44:52 GMT | 67 | ||||
0.1.0-ci-00003 | 11.91 KB | Mon, 06 Aug 2018 16:35:14 GMT | 8 |