c# - OData v4 Web API XML response nesting too deeply -
i building odata web service using webapi , odata v4.
imagine have 2 entities want expose through service: student , teacher.
now student has teacher 1 of properties , teacher has many students.
i able service return xml using trick:
ilist <odatamediatypeformatter> odataformatters = odatamediatypeformatters.create(); config.formatters.insertrange(0, odataformatters);
however xml formatter seems want format everything. mean when ask teacher, returns me students. issue arises of infinite loop each of student has teacher , teacher has students, etc. stack overflow exception.
i have tried solution proposed here of http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization#handling_circular_object_references still somehow stack overflow exception.
to around issue have had cut loop saying teacher doesn’t have students anymore loop cut , stack overflow doesn’t occur anymore. however, removes students navigation property of teacher.
is there way tell formatter respond properties, excluding navigation properties, without ignoring property through use of attribute [ignoredatamember] (i.e. don't nest)
Comments
Post a Comment