DTO mapping exception with entity in ABP

醉酒当歌 提交于 2019-12-31 03:43:08

问题


I got an error about "mapping" when I try to insert an entity.

The insert is made by the Create method of a CrudAppService. My entity inherits from FullAuditedEntity but the related DTO specifies only a few properties.

How do I handle this situation?

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

My 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; }
}

My entity:

[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; }
}

回答1:


Required mapping direction:

PostDto -> Post (Destination member list)

[AutoMapFrom(typeof(Post))] configures Post -> PostDto here:

[AutoMapFrom(typeof(Post))]
public class PostDto : EntityDto

To configure for both directions, simply do:

[AutoMap(typeof(Post))]
public class PostDto : EntityDto


来源:https://stackoverflow.com/questions/48051430/dto-mapping-exception-with-entity-in-abp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!