Skip to content

Conversation

@Tasteful
Copy link
Contributor

Adding mapping with .Include<,>() from base type

cfg.CreateMap<OrderDomain, OrderEf>()
    .EqualityComparison((oo, dto) => BaseEquals(oo, dto))
    .Include<MailOrderDomain, MailOrderEf>()
    .Include<OnlineOrderDomain, OnlineOrderEf>()
    ;

cfg.CreateMap<OnlineOrderDomain, OnlineOrderEf>()
    .EqualityComparison((ood, ooe) => DerivedEquals(ood, ooe))
    ;

cfg.CreateMap<MailOrderDomain, MailOrderEf>()
    ;

or with .IncludeBase<,>() from derived typ

cfg.CreateMap<OrderDomain, OrderEf>()
    .EqualityComparison((oo, dto) => BaseEquals(oo, dto))
    ;

cfg.CreateMap<OnlineOrderDomain, OnlineOrderEf>()
    .EqualityComparison((ood, ooe) => DerivedEquals(ood, ooe))
    .IncludeBase<OrderDomain, OrderEf>()
    ;

cfg.CreateMap<MailOrderDomain, MailOrderEf>()
    .IncludeBase<OrderDomain, OrderEf>()
    ;

the generated TypeMap is different.

The typeMap.IncludeDerivedTypes is working correctly in both case with this test

public void TypeMap_Should_include_derivied_types()
{
    var mapper = CreateMapper();
    var typeMap = mapper.ConfigurationProvider.ResolveTypeMap(typeof(OrderDomain), typeof(OrderEf));

    var typePairs = new[]{
            new TypePair(typeof(OnlineOrderDomain), typeof(OnlineOrderEf)),
            new TypePair(typeof(MailOrderDomain), typeof(MailOrderEf))
    };
    typeMap.IncludedDerivedTypes.ShouldBeEquivalentTo(typePairs);
}

The typeMap.IncludedBaseTypes is only working correctly if the mapping is on the derived

public void TypeMap_Should_include_base_types()
{
    var mapper = CreateMapper();
    var typeMap = mapper.ConfigurationProvider.ResolveTypeMap(typeof(MailOrderDomain), typeof(OrderEf));

    var typePairs = new[]{
            new TypePair(typeof(OrderDomain), typeof(OrderEf))
    };
    typeMap.IncludedBaseTypes.ShouldBeEquivalentTo(typePairs);
}

@jbogard Is this an expected behaviour or missing line in https://github.com/AutoMapper/AutoMapper/blob/877d917a2d2a20e8b6ab49d7436747a75a67e7b4/src/AutoMapper/ProfileMap.cs#L253

@Tasteful Tasteful force-pushed the issue69-include branch 2 times, most recently from 9d3727b to bedd361 Compare June 7, 2018 05:44
@Tasteful Tasteful changed the title WIP: Add test for inverted collection-include tests Add test for inverted collection-include tests Jun 7, 2018
@Tasteful
Copy link
Contributor Author

Tasteful commented Jun 7, 2018

@TylerCarlson1 Testcases is now ready to be merged, will close #69

@TylerCarlson1 TylerCarlson1 merged commit 166c5f1 into AutoMapper:development Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants