"No available constructor" 调用 AutoMapper 的 Persist().InsertOrUpdate() 时

"No available constructor" when calling AutoMapper's Persist().InsertOrUpdate()

我有一个带有默认构造函数的简单对象。我要映射到和从中映射的对象的定义完全相同,并且我已经为它们配置了一个映射器。从数据库中获取对象一切正常。

public class Tag
{
    public Guid ProjectId { get; set; }
    public Guid TagId { get; set; }
    public string Name { get; set; }
}

如果我调用 Mapper.Instance.Map(tagFrom, tagTo); 一切正常,但如果我调用 dbContext.Tags.Persist().InsertOrUpdate(tag); 我会收到此错误。

Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters

AutoMapper created this type map for you, but your types cannot be mapped using the current configuration.

AutoMapper created this type map for you, but your types cannot be mapped using the current configuration. Tag -> Expression1 (Destination member list) AKS.Common.Models.Tag -> System.Linq.Expressions.Expression1[[System.Func`2[[AKS.AppCore.Entities.Tag, AKS.AppCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] (Destination member list)

Unmapped properties:

Parameters

No available constructor.

好像是说我没有默认构造函数,但显然有一个。有人知道我做错了什么吗?

包版本: AutoMapper 8.0.0 AutoMapper.Collections 5.0.0 AutoMapper.Collections.EntityFrameworkCore 0.2.0

这可能是AutoMapper.Collections.EntityFrameworkCore中的一个bug,也可能是我自己误操作造成的。

我正在使用以下代码配置我的 Mapper

var cfg = new MapperConfigurationExpression();

cfg.AddCollectionMappers();
cfg.UseEntityFrameworkCoreModel<MyDbContext>();

cfg.CreateMap<TagDto, TagEntity>().ReverseMap();

然后我在初始化映射器之前尝试使用此代码验证我的映射配置。

var config = new MapperConfiguration(cfg);
config.AssertConfigurationIsValid();

Mapper.Initialize(cfg);

如果我删除创建 MapperConfiguration 的行并将其用于 AssertConfigurationIsValid() 然后调用 InsertOrUpdate() 工作。

我还发现如果我先初始化我的映射器,我可以调用 AssertConfigurationIsValid(),然后在 Mapper.Instance

上调用该方法
Mapper.Initialize(cfg);
Mapper.Configuration.AssertConfigurationIsValid();