Skip to content

Commit b08d857

Browse files
authored
Merge pull request #117 from AutoMapper/development
Releasing 5.0
2 parents 58f73f9 + 79126e3 commit b08d857

22 files changed

+355
-217
lines changed

Directory.Build.props

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

44
<PropertyGroup>
5+
<EFVersion>6.1.3</EFVersion>
56
<FluentAssertions>4.15.0</FluentAssertions>
67
<TestSDKVersion>15.5.0</TestSDKVersion>
78
<xUnitVersion>2.3.1</xUnitVersion>
9+
<SqlServerCompactVersion>4.0.8876.1</SqlServerCompactVersion>
810
</PropertyGroup>
911
</Project>

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
66
</configSections>
77
<entityFramework>
8-
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
8+
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
99
<parameters>
10-
<parameter value="mssqllocaldb" />
10+
<parameter value="System.Data.SqlServerCe.4.0" />
1111
</parameters>
1212
</defaultConnectionFactory>
1313
<providers>
1414
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
15+
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
1516
</providers>
1617
</entityFramework>
18+
<system.data>
19+
<DbProviderFactories>
20+
<remove invariant="System.Data.SqlServerCe.4.0" />
21+
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
22+
</DbProviderFactories>
23+
</system.data>
1724
</configuration>

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
11-
</ItemGroup>
12-
139
<ItemGroup>
1410
<ProjectReference Include="..\AutoMapper.Collection.EntityFramework\AutoMapper.Collection.EntityFramework.csproj" />
1511
</ItemGroup>
@@ -24,6 +20,15 @@
2420
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSDKVersion)" />
2521
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
2622
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
23+
<PackageReference Include="EntityFramework.SqlServerCompact" Version="$(EfVersion)" />
24+
<PackageReference Include="Microsoft.SqlServer.Compact" Version="$(SqlServerCompactVersion)" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<None Include="$(NuGetPackageRoot)\microsoft.sqlserver.compact\$(SqlServerCompactVersion)\NativeBinaries\**">
29+
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</None>
2732
</ItemGroup>
2833

2934
</Project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Entity;
4+
using System.Data.SqlServerCe;
5+
using System.Linq;
6+
using AutoMapper.EntityFramework;
7+
using AutoMapper.EquivalencyExpression;
8+
using FluentAssertions;
9+
using Xunit;
10+
11+
namespace AutoMapper.Collection.EntityFramework.Tests
12+
{
13+
public class EntityFramworkTests
14+
{
15+
public EntityFramworkTests()
16+
{
17+
Mapper.Reset();
18+
Mapper.Initialize(x =>
19+
{
20+
x.AddCollectionMappers();
21+
x.CreateMap<ThingDto, Thing>().ReverseMap();
22+
x.SetGeneratePropertyMaps<GenerateEntityFrameworkPrimaryKeyPropertyMaps<DB>>();
23+
});
24+
}
25+
26+
[Fact]
27+
public void Should_Persist_To_Update()
28+
{
29+
var db = new DB();
30+
db.Things.Add(new Thing { Title = "Test2" });
31+
db.Things.Add(new Thing { Title = "Test3" });
32+
db.Things.Add(new Thing { Title = "Test4" });
33+
db.SaveChanges();
34+
35+
Assert.Equal(3, db.Things.Count());
36+
37+
var item = db.Things.First();
38+
39+
db.Things.Persist().InsertOrUpdate(new ThingDto { ID = item.ID, Title = "Test" });
40+
Assert.Equal(1, db.ChangeTracker.Entries<Thing>().Count(x => x.State == EntityState.Modified));
41+
42+
Assert.Equal(3, db.Things.Count());
43+
44+
db.Things.First(x => x.ID == item.ID).Title.Should().Be("Test");
45+
}
46+
47+
[Fact]
48+
public void Should_Persist_To_Insert()
49+
{
50+
var db = new DB();
51+
db.Things.Add(new Thing { Title = "Test2" });
52+
db.Things.Add(new Thing { Title = "Test3" });
53+
db.Things.Add(new Thing { Title = "Test4" });
54+
db.SaveChanges();
55+
56+
Assert.Equal(3, db.Things.Count());
57+
58+
db.Things.Persist().InsertOrUpdate(new ThingDto { Title = "Test" });
59+
Assert.Equal(3, db.Things.Count());
60+
Assert.Equal(1, db.ChangeTracker.Entries<Thing>().Count(x => x.State == EntityState.Added));
61+
62+
db.SaveChanges();
63+
64+
Assert.Equal(4, db.Things.Count());
65+
66+
db.Things.OrderByDescending(x => x.ID).First().Title.Should().Be("Test");
67+
}
68+
69+
public class DB : DbContext
70+
{
71+
public DB()
72+
: base(new SqlCeConnection("Data Source=MyDatabase.sdf;Persist Security Info=False;"), contextOwnsConnection: true)
73+
{
74+
Things.RemoveRange(Things);
75+
SaveChanges();
76+
}
77+
78+
public DbSet<Thing> Things { get; set; }
79+
}
80+
81+
public class Thing
82+
{
83+
public int ID { get; set; }
84+
public string Title { get; set; }
85+
public override string ToString() { return Title; }
86+
}
87+
88+
public class ThingDto
89+
{
90+
public int ID { get; set; }
91+
public string Title { get; set; }
92+
}
93+
}
94+
}

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

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

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Collection updating support for EntityFramework with AutoMapper. Extends DBSet&lt;T&gt; with Persist&lt;TDto&gt;().InsertUpdate(dto) and Persist&lt;TDto&gt;().Delete(dto). Will find the matching object and will Insert/Update/Delete.</Description>
55
<Authors>Tyler Carlson</Authors>
6-
<TargetFramework>net45</TargetFramework>
6+
<TargetFramework>net461</TargetFramework>
77
<AssemblyName>AutoMapper.Collection.EntityFramework</AssemblyName>
88
<PackageId>AutoMapper.Collection.EntityFramework</PackageId>
99
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
@@ -12,7 +12,6 @@
1212
<AssemblyOriginatorKeyFile>../Key.snk</AssemblyOriginatorKeyFile>
1313
<SignAssembly>true</SignAssembly>
1414
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
15-
<Version>4.0.0</Version>
1615
</PropertyGroup>
1716

1817
<ItemGroup>
@@ -21,7 +20,7 @@
2120

2221
<ItemGroup>
2322
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="1.0.0" />
24-
<PackageReference Include="EntityFramework" Version="6.1.3" />
23+
<PackageReference Include="EntityFramework" Version="$(EfVersion)" />
2524
</ItemGroup>
2625

2726
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">

src/AutoMapper.Collection.EntityFramework/GenerateEntityFrameworkPrimaryKeyPropertyMatches.cs renamed to src/AutoMapper.Collection.EntityFramework/GenerateEntityFrameworkPrimaryKeyPropertyMaps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public class GenerateEntityFrameworkPrimaryKeyPropertyMaps<TDatabaseContext> : I
1717

1818
public IEnumerable<PropertyMap> GeneratePropertyMaps(TypeMap typeMap)
1919
{
20-
var propertyMaps = typeMap.GetPropertyMaps();
20+
var propertyMaps = typeMap.PropertyMaps;
2121
try
2222
{
2323
var createObjectSetMethod = _createObjectSetMethodInfo.MakeGenericMethod(typeMap.DestinationType);
2424
dynamic objectSet = createObjectSetMethod.Invoke(_context.ObjectContext, null);
2525

2626
IEnumerable<EdmMember> keyMembers = objectSet.EntitySet.ElementType.KeyMembers;
27-
var primaryKeyPropertyMatches = keyMembers.Select(m => propertyMaps.FirstOrDefault(p => p.DestinationProperty.Name == m.Name));
27+
var primaryKeyPropertyMatches = keyMembers.Select(m => propertyMaps.FirstOrDefault(p => p.DestinationMember.Name == m.Name));
2828

2929
return primaryKeyPropertyMatches;
3030
}

src/AutoMapper.Collection.LinqToSQL/AutoMapper.Collection.LinqToSQL.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Collection updating support for LinqToSQL with AutoMapper. Extends Table&lt;T&gt; with Persist&lt;TDto&gt;().InsertUpdate(dto) and Persist&lt;TDto&gt;().Delete(dto). Will find the matching object and will Insert/Update/Delete.</Description>
55
<Authors>Tyler Carlson</Authors>
6-
<TargetFramework>net45</TargetFramework>
6+
<TargetFramework>net461</TargetFramework>
77
<AssemblyName>AutoMapper.Collection.LinqToSQL</AssemblyName>
88
<PackageId>AutoMapper.Collection.LinqToSQL</PackageId>
99
<PackageIconUrl>https://s3.amazonaws.com/automapper/icon.png</PackageIconUrl>
@@ -12,7 +12,6 @@
1212
<AssemblyOriginatorKeyFile>../Key.snk</AssemblyOriginatorKeyFile>
1313
<SignAssembly>true</SignAssembly>
1414
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
15-
<Version>4.0.0</Version>
1615
</PropertyGroup>
1716

1817
<ItemGroup>
@@ -23,7 +22,7 @@
2322
<PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="1.0.0" />
2423
</ItemGroup>
2524

26-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
25+
<ItemGroup>
2726
<Reference Include="System.Data" />
2827
<Reference Include="System.Data.Linq" />
2928
<Reference Include="System" />

src/AutoMapper.Collection.LinqToSQL/GetLinqToSQLPrimaryKeyProperties.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class GetLinqToSQLPrimaryKeyProperties : IGeneratePropertyMaps
1010
{
1111
public IEnumerable<PropertyMap> GeneratePropertyMaps(TypeMap typeMap)
1212
{
13-
var propertyMaps = typeMap.GetPropertyMaps();
13+
var propertyMaps = typeMap.PropertyMaps;
1414

1515
var primaryKeyPropertyMatches = typeMap.DestinationType.GetProperties()
1616
.Where(IsPrimaryKey)
17-
.Select(m => propertyMaps.FirstOrDefault(p => p.DestinationProperty.Name == m.Name))
17+
.Select(m => propertyMaps.FirstOrDefault(p => p.DestinationMember.Name == m.Name))
1818
.ToList();
1919

2020
return primaryKeyPropertyMatches;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net461;netcoreapp1.1</TargetFrameworks>
4+
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
55
<AssemblyName>AutoMapper.Collection.Tests</AssemblyName>
66
<RootNamespace>AutoMapper.Collection</RootNamespace>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
12-
</ItemGroup>
13-
1410
<ItemGroup>
1511
<ProjectReference Include="..\AutoMapper.Collection\AutoMapper.Collection.csproj" />
1612
</ItemGroup>

0 commit comments

Comments
 (0)