Automapper - IEnumerable和嵌套集合

时间:2015-08-07 00:22:08

标签: c# automapper

我有一个遵循这个XML的嵌套结构,实体对应于外部,中间和外部。内在的对象。

<MyXml>
  <OuterObject>
    <OuterObjectID>123</OuterObjectID>
    <OuterObjectName>Out1</OuterObjectName>
    <MiddleObjectList>
      <MiddleObject>
        <MiddleObjectID>456</MiddleObjectID>
        <MiddleObjectName>Middle1</MiddleObjectName>
        <KeyRelatedToChildInnerObjects>InnerObjKey1</KeyRelatedToChildInnerObjects>
        <InnerObjectList>
          <InnerObject>
            <InnerObjectID>789</InnerObjectID>
            <InnerObjectName>Need_to_map_based_in_InnerObjKey1</InnerObjectName>
          </InnerObject>
          <InnerObject>
            <InnerObjectID>654</InnerObjectID>
            <InnerObjectName>This_too_InnerObjects_are_from_different_entity</InnerObjectName>
          </InnerObject>        
        </InnerObjectList>
      </MiddleObject>
    </MiddleObjectList>
  </OuterObject>
  <OuterObject>
    ...
  </OuterObject>
</MyXml>  

我尝试使用AutoMapper设置和填充InnerObject集合的值。这些将来自不同的实体/表,并将通过其中的父MiddleObject中所述的键相关联。我有与OuterObject和MiddleObject对应的实体/ DTO,但是在映射InnerObject时遇到了问题。谢谢你的帮助。

0 个答案:

没有答案