sharp architecture, FluentNHibernate, automapper, DTO, 1:m persistence question

Posted by csetzkorn on Stack Overflow See other posts from Stack Overflow or by csetzkorn
Published on 2010-03-30T14:20:42Z Indexed on 2010/03/30 14:23 UTC
Read the original article Hit count: 1002

Let us say we have a class A which has a reference to another class B (1:m)

public class A { public virtual B B { get; set; } }

I reflect this using FluentNHibernate within the sharp architecture and also manage to ‘initialise’ A and its B via a DTO and Automapper. The DTO contain A’s values and B (just B’s id value/A’s foreign key initialised).

I was hoping that I can persist A by ‘just’ using its 'out of the box repository' without requiring B’s repository using:

SaveOrUpdate(A);

(A has been mapped using AutoMapper and contains B with its Id initialised)

Was my assumption too naive?

Can I achieve this somehow (without ever requiring B’s repository)?

Or do I have to use A’s and B’s repository in, for example, the controller or some other service layer?

Thanks.

Best wishes,

Christian

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about automapper