I'm also interested in this topic.
We are using a single entity domain model in our project that is
mapped by NH, serves as DTO's and is also bound to the UI. It is nice
to have only one model, you don't have to add data on many places (eg.
mapping file, entity, DTO, mapper) which makes development faster. The
model is cut into independent pieces which are related by Guids
(instead of Clr references) which reduces the number of objects sent
to the client.
But we get problems because we almost can't develop a model that
serves all purposes. Sometimes we want the same objects with more or
less data. The splitting of the model could result in more database
calls or more complex queries. Database optimization and databinding
forced us to add additional redundant properties, which are actually
only used in one layer. We already started to try other approaches to
get experience, but still don't know what's best.
On Nov 28, 4:38 pm, Shane C <[EMAIL PROTECTED]> wrote:
> In fact I would say that this is a very important discussion that
> should have occurred here instead of being taken to email.
>
> Best practices & how to properly apply NHibernate are critical to
> getting it accepted by a wider audience. Your question is a very
> basic requirement to using NHibernate properly. Without knowledge
> like this existing freely and openly in the community how can we sell
> others on the value of using the technology?
>
> On Oct 7, 5:28 am, "Stefan Sedich" <[EMAIL PROTECTED]> wrote:
>
> > Amen to that, this is another attempt at designing an application in
> > this manner, and I must say I am learning alot, you learn by doing
> > these things.
>
> > I run into many issues and find it hard sometimes to just give myself
> > a sanity check to say that is ok move on. I am happy at this point but
> > have a bit to go until I am 100% satisfied. I guess another question
> > for you is when mapping aDTOto a domain say an OrderDTO which has a
> > collection of OrderItemDTO inside it do you map these children back in
> > the mapper? Or just have a AddOrderItem service method.
>
> > I know this is the NH forums and I am poluting it with unrelated
> > gander, you happy to chat over email?
>
> > Cheers again.
>
> > On Tue, Oct 7, 2008 at 9:18 PM, Gustavo Ringel <[EMAIL PROTECTED]> wrote:
> > > I like it, but you know...it's a matter of own taste, if you ask everyone
> > > in
> > > the group they will do something different, and different from what they
> > > will do in another month...we learn and improve ourselves all the time!
>
> > > Gustavo.
>
> > > On Tue, Oct 7, 2008 at 2:07 PM, Stefan Sedich <[EMAIL PROTECTED]>
> > > wrote:
>
> > >> Apart from that is it looking better?
>
> > >> Stefan Sedich
>
> > >> On 07/10/2008, at 7:53 PM, "Gustavo Ringel" <[EMAIL PROTECTED]>
> > >> wrote:
>
> > >> I personally don't like the validate there...I don't see what if it does
> > >> not validate for example.
>
> > >> If you had used NH.Validator, you can get the validation integrated with
> > >> the update and then get an exception if it is not valid...
>
> > >> Gustavo.
>
> > >> On Tue, Oct 7, 2008 at 1:28 PM, Stefan Sedich <[EMAIL PROTECTED]>
> > >> wrote:
>
> > >>> Ok refactored my code like so:
>
> > >>> public void Update(AgentUpdateDTO agentUpdateDTO) {
>
> > >>> // Use the assembler to map from thedtousing the assembler.
> > >>> Agent agent = this.agentAssembler.MapFromDTO(agentUpdateDTO);
>
> > >>> // Validate the model and use repository to update.
> > >>> agent.Validate();
> > >>> this.agentRepository.Update(agent);
>
> > >>> }
>
> > >>> The agentAssembler is injected into my service by Dependancy injection
> > >>> now which works a charm, my assembler has a MapFromDTO method which
> > >>> handles the mapping, the assembler itself is injected the required
> > >>> repositories to do the mappings the method would look like so:
>
> > >>> public override Agent MapFromDTO(AgentUpdateDTOdto) {
>
> > >>> // If id is 0 create a new agent model, otherwise
> > >>> // use repository to select the agent.
> > >>> var agent = (dto.Id == 0)
> > >>> ? new Agent()
> > >>> : this.agentRepository.SelectById(dto.Id);
>
> > >>> // Map across properties fromDTO.
> > >>> agent.Enabled =dto.Enabled;
> > >>> agent.FirstName =dto.FirstName;
> > >>> agent.Surname =dto.Surname;
> > >>> agent.UserName =dto.UserName;
> > >>> agent.RowVersion =dto.RowVersion;
>
> > >>> // Map across country if the code is set.
> > >>> if (!string.IsNullOrEmpty(dto.CountryCode))
> > >>> agent.Country =
> > >>> this.countryRepository.SelectById(dto.CountryCode);
>
> > >>> // Return the mapped agent model.
> > >>> return agent;
>
> > >>> }
>
> > >>> Do you find this better than my previous solution or do you have more
> > >>> tips for me :), I am pretty happy with the way it is working now
> > >>> though.
>
> > >>> Cheers
>
> > >>> On Mon, Oct 6, 2008 at 12:01 AM, Stefan Sedich <[EMAIL PROTECTED]>
> > >>> wrote:
> > >>> > Excellent looks like I am not totally off the rails then :)
> > >>> > Cheers
> > >>> > Stefan
>
> > >>> > On 05/10/2008, at 10:59 PM, "Gustavo Ringel" <[EMAIL PROTECTED]>
> > >>> > wrote:
>
> > >>> > I give the translators the access to the repositories they
> > >>> > require...(injection)
>
> > >>> > Gustavo.
>
> > >>> > On Sun, Oct 5, 2008 at 4:51 PM, Stefan Sedich <[EMAIL PROTECTED]>
> > >>> > wrote:
>
> > >>> >> Thanks the idea was to have a mapper to do this, one question I had I
> > >>> >> guess on this was would a mapper be able to talk to the say
> > >>> >> CountryRepository to do the attaching of the Country on our agent
> > >>> >> when
> > >>> >> mapping from aDTO?
>
> > >>> >> Cheers
>
> > >>> >> On Sun, Oct 5, 2008 at 11:44 PM, Gustavo Ringel
> > >>> >> <[EMAIL PROTECTED]> wrote:
> > >>> >> > Your Update now knows how to convert to aDTOand how to validate
> > >>> >> > and
> > >>> >> > update...i think this is a lot of responsibilities for a single
> > >>> >> > method...
>
> > >>> >> > I like more having a Translation/Convertion Class which knows both
> > >>> >> > ways...this helps you doing thinks like list.ConvertAll<AgendtDTO>
> > >>> >> > ...
> > >>> >> > and
> > >>> >> > inverse...
>
> > >>> >> > Gustavo.
>
> > >>> >> > On Sun, Oct 5, 2008 at 3:38 PM, codemonkey <[EMAIL PROTECTED]>
> > >>> >> > wrote:
>
> > >>> >> >> Hello,
>
> > >>> >> >> Just some tips really my current Service update method accepts my
> > >>> >> >> updateDTO object, uses the repository to do a select of the object
> > >>> >> >> by
> > >>> >> >> ID, maps across the properties and then does an update. Is this a
> > >>> >> >> good
> > >>> >> >> way to do this? or could I be looking at a better way? It works
> > >>> >> >> fine I
> > >>> >> >> am just looking for some constructive criticism.
>
> > >>> >> >> public void Update(AgentUpdateDTO agentUpdateDTO) {
>
> > >>> >> >> // Select from the repository by id.
> > >>> >> >> var agent =
> > >>> >> >> this.agentRepository.SelectById(agentUpdateDTO.Id);
>
> > >>> >> >> // Map across properties fromDTO.
> > >>> >> >> agent.Code = agentUpdateDTO.Code;
> > >>> >> >> agent.Commission = agentUpdateDTO.Commission;
> > >>> >> >> agent.CompanyName = agentUpdateDTO.CompanyName;
> > >>> >> >> agent.Enabled = agentUpdateDTO.Enabled;
> > >>> >> >> agent.FirstName = agentUpdateDTO.FirstName;
> > >>> >> >> agent.Gender = agentUpdateDTO.Gender;
> > >>> >> >> agent.Password = agentUpdateDTO.Password;
> > >>> >> >> agent.Surname = agentUpdateDTO.Surname;
> > >>> >> >> agent.UserName = agentUpdateDTO.UserName;
> > >>> >> >> agent.RowVersion = agentUpdateDTO.RowVersion;
>
> > >>> >> >> if (!string.IsNullOrEmpty(agentUpdateDTO.CountryCode))
> > >>> >> >> agent.Country =
>
> > >>> >> >> this.countryService.SelectByCountryCode(agentUpdateDTO.CountryCode);
>
> > >>> >> >> // Validate the model and use repository to update.
> > >>> >> >> agent.Validate();
> > >>> >> >> this.agentRepository.Update(agent);
>
> > >>> >> >> }
>
> > >>> >> >> Cheers
>
> > >>> >> --
> > >>> >> Stefan Sedich
> > >>> >> Developer
> > >>> >> Microsoft Certified Professional (MCP)
>
> > >>> --
> > >>> Stefan Sedich
> > >>> Developer
> > >>> Microsoft Certified Professional (MCP)
>
> > --
> > Stefan Sedich
> > Developer
> > Microsoft Certified Professional (MCP)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---