从m8迁移到v9后使用ProjectTo时,“参数类型不匹配”

时间:2019-08-21 08:34:00

标签: c# automapper ef-core-2.2 .net-core-2.2

迁移到最新版本的AutoMapper(从v8到v9)后,ProjectTo方法出现问题。从ICollection投影到IReadOnlyCollection时,出现System.ArgumentException:“参数类型不匹配”。

public class Source
{
    public ICollection<int> Collection { get; set; } = new HashSet<int>();
}

public class Destination
{
    public IReadOnlyCollection<int> Collection { get; set; } = new HashSet<int>();
}

public class Profile : AutoMapper.Profile
{
    public Profile() { CreateMap<Source, Destination>(); }
}

//This line throws exception
var mapped = mapper.ProjectTo<Destination>(src);

我只是想知道这是预期的行为还是错误。我在变更日志中没有发现任何相关更改。

0 个答案:

没有答案