Skip to content

Commit 0d8cfb1

Browse files
committed
Merge branch 'development'
Conflicts: src/AutoMapper.Collection/AutoMapper.Collection/AutoMapper.Collection.csproj src/AutoMapper.Collection/AutoMapper.Collection/Equivilency Expression/ExpressionExtentions.cs src/AutoMapper.Collection/AutoMapper.Collection/Properties/AssemblyInfo.cs
2 parents 205400a + 85b7a73 commit 0d8cfb1

24 files changed

Lines changed: 215 additions & 94 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
1515
</providers>
1616
</entityFramework>
17-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
17+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>AutoMapper.Collection.EntityFramework</RootNamespace>
1111
<AssemblyName>AutoMapper.Collection.EntityFramework</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
@@ -35,8 +35,8 @@
3535
<Prefer32Bit>false</Prefer32Bit>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="AutoMapper, Version=4.0.4.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
39-
<HintPath>..\packages\AutoMapper.4.0.4\lib\net45\AutoMapper.dll</HintPath>
38+
<Reference Include="AutoMapper, Version=4.2.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
39+
<HintPath>..\packages\AutoMapper.4.2.0\lib\net45\AutoMapper.dll</HintPath>
4040
<Private>True</Private>
4141
</Reference>
4242
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
@@ -68,6 +68,7 @@
6868
<ProjectReference Include="..\AutoMapper.Collection\AutoMapper.Collection.csproj">
6969
<Project>{37ad667a-8080-476c-88fd-20310ac7caf3}</Project>
7070
<Name>AutoMapper.Collection</Name>
71+
<Private>False</Private>
7172
</ProjectReference>
7273
</ItemGroup>
7374
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@@ -78,6 +79,11 @@
7879
</PropertyGroup>
7980
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
8081
</Target>
82+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
83+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
84+
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
85+
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
86+
</Target>
8187
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8288
Other similar extension points exist, see Microsoft.Common.targets.
8389
<Target Name="BeforeBuild">

src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework/Extensions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ public static class Extensions
1010
{
1111
/// <summary>
1212
/// Create a persistance object for the <see cref="T:System.Data.Entity.DbSet`1"/> to have data persisted or removed from
13+
/// Uses static API's Mapper for finding TypeMap between classes
1314
/// </summary>
1415
/// <typeparam name="TSource">Source table type to be updated</typeparam>
1516
/// <param name="source">DbSet to be updated</param>
1617
/// <returns>Persistance object to Update or Remove data</returns>
18+
[Obsolete("Use version that passes instance of IMapper")]
1719
public static IPersistance Persist<TSource>(this DbSet<TSource> source)
1820
where TSource : class
1921
{
20-
return new Persistance<TSource>(source, Mapper.Engine);
22+
return new Persistance<TSource>(source, null);
23+
}
24+
25+
/// <summary>
26+
/// Create a persistance object for the <see cref="T:System.Data.Entity.DbSet`1"/> to have data persisted or removed from
27+
/// </summary>
28+
/// <typeparam name="TSource">Source table type to be updated</typeparam>
29+
/// <param name="source">DbSet to be updated</param>
30+
/// <param name="mapper">IMapper used to find TypeMap between classes</param>
31+
/// <returns>Persistance object to Update or Remove data</returns>
32+
public static IPersistance Persist<TSource>(this DbSet<TSource> source, IMapper mapper)
33+
where TSource : class
34+
{
35+
return new Persistance<TSource>(source, mapper);
2136
}
2237

2338
/// <summary>

src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework/GenerateEntityFrameworkPrimaryKeyEquivilentExpressions.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Data.Entity.Infrastructure;
1+
using System;
2+
using System.Data.Entity.Infrastructure;
23
using AutoMapper.EquivilencyExpression;
34

45
namespace AutoMapper.EntityFramework
@@ -8,10 +9,24 @@ namespace AutoMapper.EntityFramework
89
/// </summary>
910
/// <typeparam name="TDatabaseContext">Database Context</typeparam>
1011
public class GenerateEntityFrameworkPrimaryKeyEquivilentExpressions<TDatabaseContext> : GenerateEquivilentExpressionsBasedOnGeneratePropertyMaps
11-
where TDatabaseContext : IObjectContextAdapter, new()
12+
where TDatabaseContext : IObjectContextAdapter, new()
1213
{
14+
/// <summary>
15+
/// Generate EquivilencyExpressions based on EnityFramework's primary key
16+
/// </summary>
17+
/// <param name="mapper">IMapper used to find TypeMap between classes</param>
18+
public GenerateEntityFrameworkPrimaryKeyEquivilentExpressions(IMapper mapper)
19+
: base(new GenerateEntityFrameworkPrimaryKeyPropertyMaps<TDatabaseContext>(mapper))
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Generate EquivilencyExpressions based on EnityFramework's primary key
25+
/// Uses static API's Mapper for finding TypeMap between classes
26+
/// </summary>
27+
[Obsolete("Use version that passes instance of IMapper")]
1328
public GenerateEntityFrameworkPrimaryKeyEquivilentExpressions()
14-
: base(new GenerateEntityFrameworkPrimaryKeyPropertyMaps<TDatabaseContext>())
29+
: base(new GenerateEntityFrameworkPrimaryKeyPropertyMaps<TDatabaseContext>(null))
1530
{
1631
}
1732
}

src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework/GenerateEntityFrameworkPrimaryKeyPropertyMatches.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ namespace AutoMapper.EntityFramework
1212
public class GenerateEntityFrameworkPrimaryKeyPropertyMaps<TDatabaseContext> : IGeneratePropertyMaps
1313
where TDatabaseContext : IObjectContextAdapter, new()
1414
{
15+
private readonly IMapper _mapper;
16+
1517
private readonly TDatabaseContext _context = new TDatabaseContext();
1618
private readonly MethodInfo _createObjectSetMethodInfo = typeof(ObjectContext).GetMethod("CreateObjectSet", Type.EmptyTypes);
1719

20+
public GenerateEntityFrameworkPrimaryKeyPropertyMaps(IMapper mapper)
21+
{
22+
_mapper = mapper;
23+
}
24+
1825
public IEnumerable<PropertyMap> GeneratePropertyMaps(Type srcType, Type destType)
1926
{
20-
var mapper = Mapper.FindTypeMapFor(srcType, destType);
21-
var propertyMaps = mapper.GetPropertyMaps();
27+
var typeMap = _mapper == null
28+
? (Mapper.Configuration as IConfigurationProvider).ResolveTypeMap(srcType, destType)
29+
: _mapper.ConfigurationProvider.ResolveTypeMap(srcType, destType);
30+
var propertyMaps = typeMap.GetPropertyMaps();
2231
var createObjectSetMethod = _createObjectSetMethodInfo.MakeGenericMethod(destType);
2332
dynamic objectSet = createObjectSetMethod.Invoke(_context.ObjectContext, null);
2433

src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework/Persistance.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ public class Persistance<TTo> : IPersistance
99
where TTo : class
1010
{
1111
private readonly DbSet<TTo> _sourceSet;
12-
private readonly IMappingEngine _mappingEngine;
12+
private readonly IMapper _mapper;
1313

14-
public Persistance(DbSet<TTo> sourceSet, IMappingEngine mappingEngine)
14+
public Persistance(DbSet<TTo> sourceSet, IMapper mapper)
1515
{
16-
_mappingEngine = mappingEngine;
1716
_sourceSet = sourceSet;
17+
_mapper = mapper;
1818
}
1919

2020
public void InsertOrUpdate<TFrom>(TFrom from)
2121
where TFrom : class
2222
{
23-
var equivExpr = Mapper.Map<TFrom,Expression<Func<TTo, bool>>>(from);
23+
var equivExpr = _mapper == null
24+
? Mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from)
25+
: _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
2426
if (equivExpr == null)
2527
return;
2628

@@ -31,13 +33,18 @@ public void InsertOrUpdate<TFrom>(TFrom from)
3133
to = _sourceSet.Create<TTo>();
3234
_sourceSet.Add(to);
3335
}
34-
Mapper.Map(from,to);
36+
if (_mapper == null)
37+
Mapper.Map(from, to);
38+
else
39+
_mapper.Map(from,to);
3540
}
3641

3742
public void Remove<TFrom>(TFrom from)
3843
where TFrom : class
3944
{
40-
var equivExpr = Mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
45+
var equivExpr = _mapper == null
46+
? Mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from)
47+
: _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
4148
if (equivExpr == null)
4249
return;
4350
var to = _sourceSet.FirstOrDefault(equivExpr);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.0")]
36-
[assembly: AssemblyFileVersion("1.1.0.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AutoMapper" version="4.0.4" targetFramework="net451" requireReinstallation="true" />
4-
<package id="EntityFramework" version="6.1.3" targetFramework="net451" requireReinstallation="true" />
3+
<package id="AutoMapper" version="4.2.0" targetFramework="net45" />
4+
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
5+
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
56
</packages>

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>AutoMapper.Collection.LinqToSQL</RootNamespace>
1111
<AssemblyName>AutoMapper.Collection.LinqToSQL</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
@@ -20,6 +21,7 @@
2021
<DefineConstants>DEBUG;TRACE</DefineConstants>
2122
<ErrorReport>prompt</ErrorReport>
2223
<WarningLevel>4</WarningLevel>
24+
<Prefer32Bit>false</Prefer32Bit>
2325
</PropertyGroup>
2426
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2527
<DebugType>pdbonly</DebugType>
@@ -28,32 +30,18 @@
2830
<DefineConstants>TRACE</DefineConstants>
2931
<ErrorReport>prompt</ErrorReport>
3032
<WarningLevel>4</WarningLevel>
33+
<Prefer32Bit>false</Prefer32Bit>
3134
</PropertyGroup>
3235
<ItemGroup>
33-
<Reference Include="AutoMapper, Version=4.0.4.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
34-
<HintPath>..\packages\AutoMapper.4.0.4\lib\net40\AutoMapper.dll</HintPath>
36+
<Reference Include="AutoMapper, Version=4.2.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
37+
<HintPath>..\packages\AutoMapper.4.2.0\lib\net45\AutoMapper.dll</HintPath>
3538
<Private>True</Private>
3639
</Reference>
40+
<Reference Include="Microsoft.CSharp" />
3741
<Reference Include="System" />
3842
<Reference Include="System.Core" />
39-
<Reference Include="System.Data.Linq" />
40-
<Reference Include="System.IO, Version=2.6.9.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll</HintPath>
42-
<Private>True</Private>
43-
</Reference>
44-
<Reference Include="System.Runtime, Version=2.6.9.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
45-
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll</HintPath>
46-
<Private>True</Private>
47-
</Reference>
48-
<Reference Include="System.Threading.Tasks, Version=2.6.9.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
49-
<HintPath>..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll</HintPath>
50-
<Private>True</Private>
51-
</Reference>
52-
<Reference Include="System.Xml.Linq" />
53-
<Reference Include="System.Data.DataSetExtensions" />
54-
<Reference Include="Microsoft.CSharp" />
5543
<Reference Include="System.Data" />
56-
<Reference Include="System.Xml" />
44+
<Reference Include="System.Data.Linq" />
5745
</ItemGroup>
5846
<ItemGroup>
5947
<Compile Include="GetLinqToSQLPrimaryKeyExpression.cs" />
@@ -70,6 +58,7 @@
7058
<ProjectReference Include="..\AutoMapper.Collection\AutoMapper.Collection.csproj">
7159
<Project>{37ad667a-8080-476c-88fd-20310ac7caf3}</Project>
7260
<Name>AutoMapper.Collection</Name>
61+
<Private>False</Private>
7362
</ProjectReference>
7463
</ItemGroup>
7564
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/AutoMapper.Collection/AutoMapper.Collection.LinqToSQL/GetLinqToSQLPrimaryKeyExpression.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
using AutoMapper.EquivilencyExpression;
1+
using System;
2+
using AutoMapper.EquivilencyExpression;
23

34
namespace AutoMapper.Collection.LinqToSQL
45
{
56
public class GetLinqToSQLPrimaryKeyExpression : GenerateEquivilentExpressionsBasedOnGeneratePropertyMaps
67
{
8+
/// <summary>
9+
/// Generate EquivilencyExpressions based on LinqToSQL's primary key
10+
/// </summary>
11+
/// <param name="mapper">IMapper used to find TypeMap between classes</param>
12+
public GetLinqToSQLPrimaryKeyExpression(IMapper mapper)
13+
: base(new GetLinqToSQLPrimaryKeyProperties(mapper))
14+
{
15+
}
16+
17+
/// <summary>
18+
/// Generate EquivilencyExpressions based on LinqToSQL's primary key
19+
/// Uses static API's Mapper for finding TypeMap between classes
20+
[Obsolete("Use version that passes instance of IMapper")]
21+
/// </summary>
722
public GetLinqToSQLPrimaryKeyExpression()
8-
: base(new GetLinqToSQLPrimaryKeyProperties())
23+
: base(new GetLinqToSQLPrimaryKeyProperties(null))
924
{
1025
}
1126
}

0 commit comments

Comments
 (0)