AutoMapper: What is the difference between PreserveReferences and MaxDepth?

前端 未结 2 1512
一整个雨季
一整个雨季 2020-12-18 06:13

I\'m a little bit confused. I can\'t find out the difference between PreserveReferences and MaxDepth.

Let\'s suppose we have the following

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 07:07

    MaxDepth doesn't consider object values at runtime. It simply stops mapping after the depth of the mapping tree reaches the configured value.

    PreserveReferences doesn't help with ProjectTo, MaxDepth does. If somehow, with Map, you have a mapping tree that might overflow the stack, but objects instances are not duplicated, then PreserveReferences won't help, MaxDepth will.

    MaxDepth is predictable, it stops at a hardcoded value, PreserveReferences stops only when an object instance is duplicated.

提交回复
热议问题