Skip to content

Commit 8053a13

Browse files
committed
Update to AM 9.0.0
1 parent e0a5077 commit 8053a13

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

src/AutoMapper.Collection.EntityFramework/Extensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ namespace AutoMapper.EntityFramework
99
public static class Extensions
1010
{
1111
/// <summary>
12+
/// Obsolete: Use Persist(IMapper) instead.
1213
/// Create a Persistence object for the <see cref="T:System.Data.Entity.DbSet`1"/> to have data persisted or removed from
1314
/// Uses static API's Mapper for finding TypeMap between classes
1415
/// </summary>
1516
/// <typeparam name="TSource">Source table type to be updated</typeparam>
1617
/// <param name="source">DbSet to be updated</param>
1718
/// <returns>Persistence object to Update or Remove data</returns>
19+
[Obsolete("Use Persist(IMapper) instead.", true)]
1820
public static IPersistence Persist<TSource>(this DbSet<TSource> source)
1921
where TSource : class
2022
{
21-
return new Persistence<TSource>(source, Mapper.Instance);
23+
throw new NotSupportedException();
2224
}
2325

2426
/// <summary>

src/AutoMapper.Collection.EntityFramework/Persistence.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Persistence<TTo> : IPersistence
1414
public Persistence(DbSet<TTo> sourceSet, IMapper mapper)
1515
{
1616
_sourceSet = sourceSet;
17-
_mapper = mapper;
17+
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
1818
}
1919

2020
public void InsertOrUpdate<TFrom>(TFrom from)
@@ -25,10 +25,7 @@ public void InsertOrUpdate<TFrom>(TFrom from)
2525

2626
public void InsertOrUpdate(Type type, object from)
2727
{
28-
var equivExpr = _mapper == null
29-
? Mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>
30-
: _mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>;
31-
if (equivExpr == null)
28+
if (!(_mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) is Expression<Func<TTo, bool>> equivExpr))
3229
return;
3330

3431
var to = _sourceSet.FirstOrDefault(equivExpr);
@@ -38,18 +35,13 @@ public void InsertOrUpdate(Type type, object from)
3835
to = _sourceSet.Create<TTo>();
3936
_sourceSet.Add(to);
4037
}
41-
if (_mapper == null)
42-
Mapper.Map(from, to);
43-
else
44-
_mapper.Map(from,to);
38+
_mapper.Map(from, to);
4539
}
4640

4741
public void Remove<TFrom>(TFrom from)
4842
where TFrom : class
4943
{
50-
var equivExpr = _mapper == null
51-
? Mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from)
52-
: _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
44+
var equivExpr = _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
5345
if (equivExpr == null)
5446
return;
5547
var to = _sourceSet.FirstOrDefault(equivExpr);

src/AutoMapper.Collection.LinqToSQL/Persistence.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Persistence<TTo> : IPersistence
1313

1414
public Persistence(Table<TTo> sourceSet, IMapper mapper)
1515
{
16-
_mapper = mapper;
16+
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
1717
_sourceSet = sourceSet;
1818
}
1919

@@ -25,10 +25,7 @@ public void InsertOrUpdate<TFrom>(TFrom from)
2525

2626
public void InsertOrUpdate(Type type, object from)
2727
{
28-
var equivExpr = _mapper == null
29-
? Mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>
30-
: _mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) as Expression<Func<TTo, bool>>;
31-
if (equivExpr == null)
28+
if (!(_mapper.Map(from, type, typeof(Expression<Func<TTo, bool>>)) is Expression<Func<TTo, bool>> equivExpr))
3229
return;
3330

3431
var to = _sourceSet.FirstOrDefault(equivExpr);
@@ -38,18 +35,13 @@ public void InsertOrUpdate(Type type, object from)
3835
to = Activator.CreateInstance<TTo>();
3936
_sourceSet.InsertOnSubmit(to);
4037
}
41-
if (_mapper == null)
42-
Mapper.Map(from, to);
43-
else
44-
_mapper.Map(from, to);
38+
_mapper.Map(from, to);
4539
}
4640

4741
public void Remove<TFrom>(TFrom from)
4842
where TFrom : class
4943
{
50-
var equivExpr = _mapper == null
51-
? Mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from)
52-
: _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
44+
var equivExpr = _mapper.Map<TFrom, Expression<Func<TTo, bool>>>(from);
5345
if (equivExpr == null)
5446
return;
5547
var to = _sourceSet.FirstOrDefault(equivExpr);

src/AutoMapper.Collection.LinqToSQL/PersistenceExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ namespace AutoMapper.Collection.LinqToSQL
99
public static class PersistenceExtensions
1010
{
1111
/// <summary>
12+
/// Obsolete: Use Persist(IMapper) instead.
1213
/// Create a Persistence object for the <see cref="T:System.Data.Entity.DbSet`1"/> to have data persisted or removed from
1314
/// Uses static API's Mapper for finding TypeMap between classes
1415
/// </summary>
1516
/// <typeparam name="TSource">Source table type to be updated</typeparam>
1617
/// <param name="source">Table to be updated</param>
1718
/// <returns>Persistence object to Update or Remove data</returns>
19+
[Obsolete("Use Persist(IMapper) instead.", true)]
1820
public static IPersistence Persist<TSource>(this Table<TSource> source)
1921
where TSource : class
2022
{
21-
return new Persistence<TSource>(source, Mapper.Instance);
23+
throw new NotSupportedException();
2224
}
2325

2426
/// <summary>

src/AutoMapper.Collection/AutoMapper.Collection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="AutoMapper" Version="8.1.0" />
19+
<PackageReference Include="AutoMapper" Version="9.0.0" />
2020
</ItemGroup>
2121

2222
</Project>

0 commit comments

Comments
 (0)