【问题标题】:Automapper, Partial map big DTO with associationsAutomapper,带关联的部分映射大 DTO
【发布时间】:2013-12-11 04:57:40
【问题描述】:

我想将我的实体列表映射到 DTO 列表,而不与其他 DTO 关联。

例如: http://mysite.local/api/documents 返回 DocumentDTO 列表,

但请求http://mysite.local/api/documents/DA49BC12-CFAB-496A-B3D9-A26200F3E76C 返回带有关联、子对象的详细 DocumentDTO 对象。

也许我应该为我的 Document 实体定义两个 DTO? (DocumentListItemDTO、DocumentDetailDTO)。或者我可以使用 AutoMapper 将我的实体部分映射到 dto?

【问题讨论】:

    标签: asp.net asp.net-mvc-4 asp.net-web-api automapper dto


    【解决方案1】:

    您也可以使用 odata 仅选择您需要的字段,例如 http://mysite.local/documents?$select=Id,Name

    但如果你真的希望列表对象不同,那么我想细节对象应该是不同的对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-13
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多