ABP 中实体的 DTO 映射异常

ale*_*lex 1 c# automapper aspnetboilerplate

当我尝试插入一个实体时,我收到了一个关于“映射”的错误。

插入是通过CreateCrudAppService的方法进行的。我的实体继承自FullAuditedEntity但相关的 DTO 仅指定了几个属性。

我该如何处理这种情况?

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
==========================================================================
PostDto -> Post (Destination member list)
MaiPiuSprechi.Domain.Posts.Dto.PostDto -> MaiPiuSprechi.Domain.Posts.Post (Destination member list)

Unmapped properties:
Items
IsDeleted
DeleterUser
DeleterUserId
DeletionTime
CreatorUser
LastModifierUser
LastModificationTime
LastModifierUserId
CreationTime
CreatorUserId
Run Code Online (Sandbox Code Playgroud)

我的 DTO:

[AutoMapFrom(typeof(Post))]
public class PostDto : EntityDto
{
    [Required]
    public string Description { get; set; }
    public string Note { get; set; }
    public DateTime? Scadenza { get; set; }

    [Required]
    public string Zona { get; set; }
    public TipoPost Tipo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的实体:

[Table("AbpPosts")]
public class Post : FullAuditedEntity<int,User>
{
    public Post()
    {
        // CreationTime = DateTime.Now;
    }

    public Post(string description, string zona)
    {
        Description = description;
        Zona = zona;
    }

    public Post(string description, string zona, TipoPost tipo)
    {
        Description = description;
        Zona = zona;
        Tipo = tipo;
    }

    [Required]
    public string Description { get; set; }
    public string Note { get; set; }
    public DateTime? Scadenza { get; set; }

    [Required]
    public string Zona { get; set; }

    [NotMapped]
    public virtual ICollection<Item> Items { get; set; }
    public TipoPost Tipo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

aar*_*ron 6

所需的映射方向:

PostDto -> Post(目的地成员列表)

[AutoMapFrom(typeof(Post))]Post -> PostDto在这里配置:

[AutoMapFrom(typeof(Post))]
public class PostDto : EntityDto
Run Code Online (Sandbox Code Playgroud)

要配置两个方向,只需执行以下操作:

[AutoMap(typeof(Post))]
public class PostDto : EntityDto
Run Code Online (Sandbox Code Playgroud)