ASP.NET MVC JSON over Fluent Nhibernate Model -
ASP.NET MVC JSON over Fluent Nhibernate Model -
i trying homecoming jsonresult using mvc controller standard json(object) method. object of type model1 built fluent nhibernate.
model1 has property of type model2. in debug mode see environment creates proxy descendant class of model2 called castle.proxies.model2proxy. used internally fluent nhibernate, believe, satisfy mappings. , in run time, actual model1.model2 of type castle.proxies.model2proxy.
the problem when model1 serialized, model2 beingness serialized too. , serializer seems seek serialize properties of object, including generated castle , not needed me. ok if did not cause exception. namely, somewhere within object circular reference presents , exception caused it. here exception text:
system.invalidoperationexception: circular reference detected while serializing object of type 'system.reflection.runtimemodule'
i double checked domain , found no circular references there, blaming castle. correct? castle blame that? if so, options? how tell serializer ignore castle properties? particularly, how tell serialize defined type, not actual one?
i tend covering domain models viewmodels fighting issue, recommended approach, love know cure, if exists.
in general, it's not practice serialize model entities. because want have finish command on serialize , send client. when serialize model entities, might serializing whole object graph associated them, don't need / want. (for example- if want user view model1 entity, might sending along model2 entity, along model3 collection etc.)
the standard way deal using sort of dtos, adapted display exactly want display. example:
public class model1dto { public int id; public string name; public string model2name; //whatever other properties need display } asp.net-mvc fluent-nhibernate castle javascriptserializer
Comments
Post a Comment