Unfortunately, there really is no good way out of manually doing the
work for the DTO. I've written a mapping library to map one object to
another that did custom conversions and automatic two way mappings ---
but in hindsight, it just isn't worth the effort. In it really easy
to debug and unit test a class that is written like:
dto.FirstName = entity.LastName;
dto.LastName = entity.LastName;
foreach (var phoneNumber in entity.PhoneNumbers) { ... }
although it is certainly tedious. If you are interested in mapping
frameworks, I recently saw this: http://www.codeplex.com/AutoMapper,
but I never looked at it so I can't comment on it.
Unless your entities have a ridiculous amount of fields, I would just
consider writing the code by hand.
On Jan 30, 5:32 pm, caiokf <[email protected]> wrote:
> Thank you all for the replies.
>
> @Eric and Shane.
>
> How would it be to work with unit tests with that approach? Now I'm
> using in-memory repositories for the nh entities, and it's very easy
> to unit testing. Do you think I will have to put some more effort in
> order to unit test my app using DTOs, or it's just a matter of habit?
>
> On 30 jan, 20:03, Shane C <[email protected]> wrote:
>
> > Agreed with Eric. I would think very carefully before pass domain
> > objects back over the wire.
>
> > On Jan 30, 1:03 pm, Eric Hauser <[email protected]> wrote:
>
> > > The biggest pitfall to consider is how much data will be serialized
> > > when you expose your entities over WCF. For instance, you can map a
> > > collection that may be very large on an object and if you are not lazy
> > > loading, all of that data will be serialized over the web service.
>
> > > The answer really is "it depends", but assuming this is an large
> > > project, I always consider my web service contracts to be data
> > > transfer objects. Explicitly copy the data from the entities onto the
> > > contract. It is best to think of web service objects as messages and
> > > not entities. There should be a decent amount of information on this
> > > subject if you do some searching.
>
> > > On Jan 30, 1:48 pm, Fabio Maulo <[email protected]> wrote:
>
> > > > AFIK the only thing you must take care when you work with NH+WCF is the
> > > > nh-session management for each WCF class/method.
>
> > > > 2009/1/30 caiokf <[email protected]>
>
> > > > > Hi,
>
> > > > > I'm starting a new project using NHibernate, and I wonder if some of
> > > > > you had experience with this kind of project:
>
> > > > > The project includes more than one application accessing the same data
> > > > > store (winforms and asp.net apps).
> > > > > I though about using NHibernate, with Fluent NHibernate for Mapping
> > > > > and Repositories.
> > > > > Now I'm thinking about expose the NHibernate domain entities by WCF
> > > > > (so the different projects could use them), and as I never worked with
> > > > > NHibernate+WCF, I would like to know of any possible pitfalls and what
> > > > > are the best practices to do so, or if anyone knows any better suited
> > > > > option.
>
> > > > > I would appreciate any idea.
>
> > > > > Thanks,
> > > > > Caio
>
> > > > --
> > > > Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---