GithubHelp home page GithubHelp logo

Comments (2)

asbjornu avatar asbjornu commented on July 20, 2024

Hi. What you want to do is not recommended practice. You shouldn't directly expose your NHibernate object model to serialization because you won't be in (full) control over what is serialized and how. Especially with lazy loaded references, many-to-many and such, the performance can really suffer.

You should instead, as you write, use AutoMapper or something similar to map just the data you want from the domain model to DTO objects that is then serialized. It's the same with ViewModels in MVC too; you should map and expose only the data you need for your view and not the entire domain model. This gives you precise control over what is exposed and how it performs.

So while there are hacks you can apply to make your use-case work, I'd strongly recommend you to avoid it and instead just do the mapping. Yes, it's a bit tedious to create the DTO objects, but it will be worth it. Jimmy Bogard (the author of AutoMapper) has written about this exact subject, which is highly recommended reading.

from yaxlib.

katlimruiz avatar katlimruiz commented on July 20, 2024

Many thanks for the answer, indeed this is what Im going to do.

My DTOs inherit from the model (just to automatically have fields added) and for all complex properties (not primitives) I've put YAXDoNotSerialize, so I do mapping for them with AutoMapper and also have the YaxSerializeAs on the class declaration so the xml does not show the DTOs names.

from yaxlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.