具有ABP中实体的DTO映射异常 [英] DTO mapping exception with entity in ABP

查看:386
本文介绍了具有ABP中实体的DTO映射异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试插入实体时,出现有关映射"的错误.

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

插入是通过CrudAppService的Create方法完成的. 我的实体继承自FullAuditedEntity,但是相关的DTO仅指定了一些属性.

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.

如何处理这种情况?

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

我的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; }
}

我的实体:

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

推荐答案

所需的映射方向:

PostDto->发布(目标成员列表)

PostDto -> Post (Destination member list)

[AutoMapFrom(typeof(Post))]在此处配置Post -> PostDto:

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

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

To configure for both directions, simply do:

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

这篇关于具有ABP中实体的DTO映射异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆