0

I have two objects

class Order{ public List<Case> Cases {get;set;} }
class Case { public Order Order {get;set;}

I map them using Automapper 5.2.0

CreateMap<CustomerOrder, Order>().PreserveReferences()
.ForMember(d=>d.Case, o=>o.MapFrom(s=>s.Case));

CreateMap<OrderCase, Case>().PreserveReferences()
.ForMember(d=>d.Order, o=>MapFrom(s=>s.Order))

Got a circular reference and stack overflow.

UPDATE Not exactly Circular reference causing stack overflow with Automapper

When I map an Order, I need to receive an Order with multiple Cases

  • Order
    • Case (.Order must be null or reference to parent order)
    • Case (the same)

Also when I map Case I need the corresponding Order to be filled.

  • Case
    • Order (no cases)
Community
  • 1
  • 1
nelly2k
  • 781
  • 1
  • 10
  • 28
  • I think you need to have one of the 2 ignored by automapper and handle it yourself. Or check this one out:http://stackoverflow.com/questions/11505128/circular-reference-causing-stack-overflow-with-automapper – Etienne Mar 29 '17 at 02:51
  • 1
    Possible duplicate of [Circular reference causing stack overflow with Automapper](http://stackoverflow.com/questions/11505128/circular-reference-causing-stack-overflow-with-automapper) – Keith Nicholas Mar 29 '17 at 03:15
  • I tried solution from post you referring to, but unfortunately it is not exactly I need. I will update my post to clarify in minute – nelly2k Mar 29 '17 at 03:18
  • Still sounds like the solution in the previous one? – Keith Nicholas Mar 29 '17 at 03:25
  • When I map case the order is null – nelly2k Mar 29 '17 at 03:28
  • can you show an example of something that's not mapping the way you want? – Keith Nicholas Mar 29 '17 at 19:57

0 Answers0