Mappings needed

2008/9/13 codemonkey <[EMAIL PROTECTED]>

>
> Hello,
>
> Having a slight issue and would like some solutions/suggestions, I
> have for example 2 tables. TableA and TableB (mind my names), The
> tables Look like so:
>
> TableA
> ----------
> Id
> Name
> RowVersion
>
> TableB
> ----------
> Id
> TableAId
> Name
> RowVersion
>
>
> I have a service method which inserts a new TableB, this talks to my
> repository to do an insert.
>
> public void Insert(TableB entity) {
>    entity.Validate();
>    repository.Insert(entity);
> }
>
>
> No here is my issue, on my view I am passing in a new TableB like
> this, the below is a view method which builds up the entity and passes
> off to the service:
>
> // Build entity
> TableB entity = new TableB();
> entity.Id = view.Id;
> entity.TableA = new TableA() {
>    Id = view.TableAId;
> };
> entity.Name = view.Name;
> entity.RowVersion = view.RowVersion;
>
> // Pass to service
> service.Insert(entity);
>
>
> With mapping the TableA relationship I am just setting the Id hoping
> NH will sort it out, but due to the rowversion is null it thinks it is
> transient so it is creating a new TableB entity. One solution I came
> up with was in my presenter use the TableA service to resolve by Id
> and attach, this works fine, but puts this login in my presenter
> (yuck).
>
> So my current solution is to change my service method to check if the
> TableA's Id is set then use the repository for TableA to resolve by Id
> and then attach it like this. Seems to work ok for now.
>
> Has anyone got any suggestions for me on this topic on how I can make
> this easier?
>
>
> Cheers
> Stefan
>
>
>
>
>
>
> >
>


-- 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to