Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion AgileMapper/Configuration/UserConfigurationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ public void Add(EntityKeyMappingSetting setting)
}

public bool MapEntityKeys(IBasicMapperData basicData)
=> _entityKeyMappingSettings?.FirstOrDefault(s => s.AppliesTo(basicData))?.MapKeys == true;
{
var applicableSetting = _entityKeyMappingSettings?
.FirstOrDefault(s => s.AppliesTo(basicData))?
.MapKeys;

return (applicableSetting == true) ||
(basicData.RuleSet.Settings.AllowEntityKeyMapping && (applicableSetting != false));
}

#endregion

Expand Down
1 change: 1 addition & 0 deletions AgileMapper/MappingRuleSetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class MappingRuleSetCollection
{
UseMemberInitialisation = true,
UseSingleRootMappingExpression = true,
AllowEntityKeyMapping = true,
AllowCloneEntityKeyMapping = true,
GuardAccessTo = value => value.Type.IsComplex(),
ExpressionIsSupported = value => value.CanBeProjected(),
Expand Down
2 changes: 2 additions & 0 deletions AgileMapper/MappingRuleSetSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public static MappingRuleSetSettings ForInMemoryMapping(

public bool CheckDerivedSourceTypes { get; set; }

public bool AllowEntityKeyMapping { get; set; }

public bool AllowCloneEntityKeyMapping { get; set; }

public Func<Expression, bool> GuardAccessTo { get; set; }
Expand Down
21 changes: 13 additions & 8 deletions AgileMapper/Members/MemberMapperDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace AgileObjects.AgileMapper.Members
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#if NET35
using Microsoft.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using System.Reflection;
using Configuration;
using DataSources;
Expand All @@ -12,12 +17,8 @@ namespace AgileObjects.AgileMapper.Members
using Extensions.Internal;
using NetStandardPolyfills;
using ObjectPopulation;
#if NET35
using Microsoft.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using static Member;
using static System.StringComparison;

internal static class MemberMapperDataExtensions
{
Expand All @@ -26,7 +27,10 @@ public static bool TargetTypeIsEntity(this IMemberMapperData mapperData)

public static bool IsEntity(this IMemberMapperData mapperData, Type type, out Member idMember)
{
if (type == null)
if ((type == null) ||
type.Name.EndsWith("ViewModel", Ordinal) ||
type.Name.EndsWith("Dto", Ordinal) ||
type.Name.EndsWith("DataTransferObject", Ordinal))
{
idMember = null;
return false;
Expand Down Expand Up @@ -210,8 +214,9 @@ public static bool TargetMemberIsUnmappable<TTMapperData>(

// If we're here:
// 1. TargetMember is an Entity key
// 2. No configuration exists to allow Entity key Mapping
// 3. No configured data sources exist
// 2. The rule set doesn't allow entity key mapping
// 3. No configuration exists to allow Entity key Mapping
// 4. No configured data sources exist

if (mapperData.RuleSet.Settings.AllowCloneEntityKeyMapping &&
(mapperData.SourceType == mapperData.TargetType))
Expand Down