c# - Automapper parent-child self referencing loop -
i'm trying map list model object kid has reference parent. json serialization throw "self referencing loop detected" error message. model classes:
public class event { public int id { get; set; } public string name { get; set; } public icollection<eventelement> eventelements { get; set; } ... } public class eventelement { public int id { get; set; } ... public int eventid { get; set; } public virtual event event { get; set; } }
i had tried tricks in automapper configuration. first, throw same error: mapper.createmap() .formember(vm => vm.eventelements, opt => opt.mapfrom(src => src.eventelements));
second, homecoming null each object in list: mapper.createmap().maxdepth(1);
how can event info childs without circular loop?
you need disable proxy creation in dbcontext below:
dbcontext.configuration.proxycreationenabled = false;
and utilize "include" lambda look in repository
public iqueryable<customer> getallcustomers() { homecoming dbset.asqueryable().include(s => s.statustype).include(s => s.customercategory); }
c# automapper-3
No comments:
Post a Comment