Skip to content

Commit 40dddc6

Browse files
Merge pull request #137 from AutoMapper/development
Development
2 parents 582dd7f + 20f5cfa commit 40dddc6

30 files changed

+417
-329
lines changed

AutoMapper.Collection.sln

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2010
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29411.108
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{19AAEE83-5EEC-4EAA-9CF7-16F8ED58B50E}"
77
ProjectSection(SolutionItems) = preProject
@@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{19AAEE
1010
EndProject
1111
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{578F2483-CF08-409D-A316-31BCB7C5D9D0}"
1212
ProjectSection(SolutionItems) = preProject
13+
appveyor.yml = appveyor.yml
1314
Directory.Build.props = Directory.Build.props
1415
global.json = global.json
1516
README.md = README.md
@@ -22,9 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.Collection.Entit
2223
EndProject
2324
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.Collection.LinqToSQL", "src\AutoMapper.Collection.LinqToSQL\AutoMapper.Collection.LinqToSQL.csproj", "{A0A023B6-D02A-4CD3-9B3D-3B3022DB001A}"
2425
EndProject
25-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapper.Collection.Tests", "src\AutoMapper.Collection.Tests\AutoMapper.Collection.Tests.csproj", "{2D3D34AD-6A0A-4382-9A2F-894F52D184A7}"
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.Collection.Tests", "src\AutoMapper.Collection.Tests\AutoMapper.Collection.Tests.csproj", "{2D3D34AD-6A0A-4382-9A2F-894F52D184A7}"
2627
EndProject
27-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapper.Collection.EntityFramework.Tests", "src\AutoMapper.Collection.EntityFramework.Tests\AutoMapper.Collection.EntityFramework.Tests.csproj", "{BDE127AB-AC3F-44DF-BC33-210DAFD12E15}"
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoMapper.Collection.EntityFramework.Tests", "src\AutoMapper.Collection.EntityFramework.Tests\AutoMapper.Collection.EntityFramework.Tests.csproj", "{BDE127AB-AC3F-44DF-BC33-210DAFD12E15}"
2829
EndProject
2930
Global
3031
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Directory.Build.props

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
<Import Project="version.props" />
33

44
<PropertyGroup>
5-
<EFVersion>6.1.3</EFVersion>
65
<FluentAssertions>4.15.0</FluentAssertions>
76
<TestSDKVersion>15.5.0</TestSDKVersion>
8-
<xUnitVersion>2.3.1</xUnitVersion>
9-
<SqlServerCompactVersion>4.0.8876.1</SqlServerCompactVersion>
7+
<xUnitVersion>2.4.1</xUnitVersion>
8+
<EffortVersion>2.2.1</EffortVersion>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
12+
<EFVersion>6.1.3</EFVersion>
1013
</PropertyGroup>
14+
15+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp3.0' ">
16+
<EFVersion>6.3.0</EFVersion>
17+
</PropertyGroup>
18+
1119
</Project>

README.md

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,88 @@
11
<img src="https://s3.amazonaws.com/automapper/logo.png" alt="AutoMapper">
22

3-
AutoMapper.Collection
4-
================================
3+
# AutoMapper.Collection
54
Adds ability to map collections to existing collections without re-creating the collection object.
65

76
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.
87

9-
How to add to AutoMapper?
10-
--------------------------------
8+
## How to add to AutoMapper?
119
Call AddCollectionMappers when configuring
12-
13-
Mapper.Initialize(cfg =>
14-
{
15-
cfg.AddCollectionMappers();
16-
// Configuration code
17-
});
10+
```
11+
Mapper.Initialize(cfg =>
12+
{
13+
cfg.AddCollectionMappers();
14+
// Configuration code
15+
});
16+
```
1817
Will add new IObjectMapper objects into the master mapping list.
1918

20-
Adding equivalency between two classes
21-
--------------------------------
19+
## Adding equivalency between two classes
2220
Adding equivalence to objects is done with EqualityComparison extended from the IMappingExpression class.
23-
24-
cfg.CreateMap<OrderItemDTO, OrderItem>().EqualityComparison((odto, o) => odto.ID == o.ID);
21+
```
22+
cfg.CreateMap<OrderItemDTO, OrderItem>().EqualityComparison((odto, o) => odto.ID == o.ID);
23+
```
2524
Mapping OrderDTO back to Order will compare Order items list based on if their ID's match
26-
27-
Mapper.Map<List<OrderDTO>,List<Order>>(orderDtos, orders);
25+
```
26+
Mapper.Map<List<OrderDTO>,List<Order>>(orderDtos, orders);
27+
```
2828
If ID's match will map OrderDTO to Order
2929

3030
If OrderDTO exists and Order doesn't add to collection
3131

3232
If Order exists and OrderDTO doesn't remove from collection
3333

34-
Why update collection? Just recreate it
35-
-------------------------------
34+
## Why update collection? Just recreate it
3635
ORMs don't like setting the collection, so you need to add and remove from preexisting one.
3736

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

40-
Can it just figure out the ID equivalency for me in EF?
41-
-------------------------------
42-
Automapper.Collection.EntityFramework can do that for you.
43-
44-
Mapper.Initialize(cfg =>
45-
{
46-
cfg.AddCollectionMappers();
47-
cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkPrimaryKeyPropertyMaps<DB>>();
48-
// Configuration code
49-
});
39+
## Can it just figure out the ID equivalency for me in Entity Framework?
40+
`Automapper.Collection.EntityFramework` or `Automapper.Collection.EntityFrameworkCore` can do that for you.
41+
42+
```
43+
Mapper.Initialize(cfg =>
44+
{
45+
cfg.AddCollectionMappers();
46+
cfg.SetGeneratePropertyMaps<GenerateEntityFrameworkPrimaryKeyPropertyMaps<DB>>();
47+
// Configuration code
48+
});
49+
```
5050
User defined equality expressions will overwrite primary key expressions.
5151

52-
What about comparing to a single existing Entity for updating?
53-
--------------------------------
52+
## What about comparing to a single existing Entity for updating?
5453
Automapper.Collection.EntityFramework does that as well through extension method from of DbSet<TEntity>.
5554

5655
Translate equality between dto and EF object to an expression of just the EF using the dto's values as constants.
57-
58-
dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(newOrderDto);
59-
dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(existingOrderDto);
60-
dbContext.Orders.Persist().Remove<OrderDTO>(deletedOrderDto);
61-
dbContext.SubmitChanges();
56+
```
57+
dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(newOrderDto);
58+
dbContext.Orders.Persist().InsertOrUpdate<OrderDTO>(existingOrderDto);
59+
dbContext.Orders.Persist().Remove<OrderDTO>(deletedOrderDto);
60+
dbContext.SubmitChanges();
61+
```
6262
**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.
6363

6464
Persist doesn't call submit changes automatically
6565

66-
How to get it
67-
--------------------------------
68-
On Nuget
66+
## Where can I get it?
67+
68+
First, [install NuGet](http://docs.nuget.org/docs/start-here/installing-nuget). Then, install [AutoMapper.Collection](https://www.nuget.org/packages/AutoMapper.Collection/) from the package manager console:
69+
```
70+
PM> Install-Package AutoMapper.Collection
71+
```
72+
73+
### Additional packages
74+
75+
#### AutoMapper Collection for Entity Framework
76+
```
77+
PM> Install-Package AutoMapper.Collection.EntityFramework
78+
```
6979

70-
PM> Install-Package AutoMapper.Collection
71-
PM> Install-Package AutoMapper.Collection.EntityFramework
72-
Also have AutoMapper.LinqToSQL
80+
#### AutoMapper Collection for Entity Framework Core
81+
```
82+
PM> Install-Package AutoMapper.Collection.EntityFrameworkCore
83+
```
7384

74-
PM> Install-Package AutoMapper.Collection.LinqToSQL
85+
#### AutoMapper Collection for LinqToSQL
86+
```
87+
PM> Install-Package AutoMapper.Collection.LinqToSQL
88+
```

appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ branches:
55
only:
66
- master
77
- development
8-
image: Visual Studio 2017
8+
image: Visual Studio 2019
99
nuget:
1010
disable_publish_on_pr: true
11+
environment:
12+
DOTNET_CLI_VERSION: 3.0.100
13+
DOTNET_CLI_TELEMETRY_OPTOUT: true
1114
build_script:
1215
- cmd: .\build.cmd
1316
test: off

build.ps1

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ task compile -depends clean {
3838
$buildParam = @{ $true = ""; $false = "--version-suffix=$buildSuffix"}[$tag -ne $NULL -and $revision -ne "local"]
3939
$packageParam = @{ $true = ""; $false = "--version-suffix=$suffix"}[$tag -ne $NULL -and $revision -ne "local"]
4040

41-
echo "build: Tag is $tag"
42-
echo "build: Package version suffix is $suffix"
43-
echo "build: Build version suffix is $buildSuffix"
41+
Write-Output "build: Tag is $tag"
42+
Write-Output "build: Package version suffix is $suffix"
43+
Write-Output "build: Build version suffix is $buildSuffix"
4444

4545
# restore all project references (creating project.assets.json for each project)
4646
exec { dotnet restore $base_dir\AutoMapper.Collection.sln /nologo }
4747

48-
exec { dotnet build $base_dir\AutoMapper.Collection.sln -c $config $buildParam /nologo --no-restore }
48+
exec { dotnet build $base_dir\AutoMapper.Collection.sln -c $config $buildParam --no-restore /nologo }
4949

50-
exec { dotnet pack $base_dir\AutoMapper.Collection.sln -c $config --include-symbols --no-build --no-restore --output $artifacts_dir $packageParam /nologo}
50+
exec { dotnet pack $base_dir\AutoMapper.Collection.sln -c $config --include-symbols --no-build --no-restore --output $artifacts_dir $packageParam /nologo }
5151
}
5252

5353
task test {
@@ -60,29 +60,30 @@ task test {
6060

6161
function Install-Dotnet
6262
{
63-
$dotnetcli = where-is('dotnet')
63+
$dotnetCli = (where-is "dotnet" | Select-Object -First 1)
64+
$install = ($null -eq $dotnetCli -or ($null -ne $env:DOTNET_CLI_VERSION -and $null -eq (&"$dotnetCli" --info | Where-Object { $_ -like " $env:DOTNET_CLI_VERSION*" })))
6465

65-
if($dotnetcli -eq $null)
66-
{
66+
if ($install)
67+
{
6768
$dotnetPath = "$pwd\.dotnet"
68-
$dotnetCliVersion = if ($env:DOTNET_CLI_VERSION -eq $null) { 'Latest' } else { $env:DOTNET_CLI_VERSION }
69-
$dotnetInstallScriptUrl = 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/install.ps1'
70-
$dotnetInstallScriptPath = '.\scripts\obtain\install.ps1'
69+
$dotnetCliVersion = if ($null -eq $env:DOTNET_CLI_VERSION) { 'Latest' } else { $env:DOTNET_CLI_VERSION }
70+
$dotnetInstallScriptUrl = 'https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.ps1'
71+
$dotnetInstallScriptPath = '.\scripts\obtain\dotnet-install.ps1'
7172

72-
md -Force ".\scripts\obtain\" | Out-Null
73-
curl $dotnetInstallScriptUrl -OutFile $dotnetInstallScriptPath
74-
& .\scripts\obtain\install.ps1 -Channel "preview" -version $dotnetCliVersion -InstallDir $dotnetPath -NoPath
73+
mkdir -Force ".\scripts\obtain\" | Out-Null
74+
Invoke-WebRequest $dotnetInstallScriptUrl -OutFile $dotnetInstallScriptPath
75+
& .\scripts\obtain\dotnet-install.ps1 -Channel "preview" -version $dotnetCliVersion -InstallDir $dotnetPath -NoPath
7576
$env:Path = "$dotnetPath;$env:Path"
7677
}
7778
}
7879

7980
function where-is($command) {
80-
(ls env:\path).Value.split(';') | `
81-
where { $_ } | `
82-
%{ [System.Environment]::ExpandEnvironmentVariables($_) } | `
83-
where { test-path $_ } |`
84-
%{ ls "$_\*" -include *.bat,*.exe,*cmd } | `
85-
%{ $file = $_.Name; `
81+
(Get-ChildItem env:\path).Value.split(';') | `
82+
Where-Object { $_ } | `
83+
ForEach-Object{ [System.Environment]::ExpandEnvironmentVariables($_) } | `
84+
Where-Object { test-path $_ } |`
85+
ForEach-Object{ Get-ChildItem "$_\*" -include *.bat,*.exe,*cmd } | `
86+
ForEach-Object{ $file = $_.Name; `
8687
if($file -and ($file -eq $command -or `
8788
$file -eq ($command + '.exe') -or `
8889
$file -eq ($command + '.bat') -or `
@@ -91,5 +92,5 @@ function where-is($command) {
9192
$_.FullName `
9293
} `
9394
} | `
94-
select -unique
95+
Select-Object -unique
9596
}

src/AutoMapper.Collection.EntityFramework.Tests/App.config

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/AutoMapper.Collection.EntityFramework.Tests/AssemblyInfo.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/AutoMapper.Collection.EntityFramework.Tests/AutoMapper.Collection.EntityFramework.Tests.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net461</TargetFrameworks>
4+
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
55
<AssemblyName>AutoMapper.Collection.EntityFramework.Tests</AssemblyName>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -10,18 +10,12 @@
1010
<ProjectReference Include="..\AutoMapper.Collection.EntityFramework\AutoMapper.Collection.EntityFramework.csproj" />
1111
</ItemGroup>
1212

13-
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
14-
<Reference Include="System" />
15-
<Reference Include="Microsoft.CSharp" />
16-
</ItemGroup>
17-
1813
<ItemGroup>
1914
<PackageReference Include="FluentAssertions" Version="$(FluentAssertions)" />
2015
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSDKVersion)" />
2116
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
2217
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
23-
<PackageReference Include="EntityFramework.SqlServerCompact" Version="$(EfVersion)" />
24-
<PackageReference Include="Microsoft.SqlServer.Compact" Version="$(SqlServerCompactVersion)" />
18+
<PackageReference Include="Effort.EF6" Version="$(EffortVersion)" />
2519
</ItemGroup>
2620

2721
<ItemGroup>

0 commit comments

Comments
 (0)