Hi,

I have a seemingly simple situation. I have a customer with a bunch of
contacts (simple value objects). I map the contacts as an idbag (see
mapping at end of message). Adding a contact to a customer is simple
and works fine. My problem occurs when wanting to remove or modify a
contact. Here's how a contact would be removed:

- the UI requests a customer,
- the customer is sent to the UI as a DTO via WCF, including the list
of contacts (with their surrogate ID value),
- in the UI, the user deletes a contact of the customer,
- a DeleteContactCommand, having the customers ID and the contacts ID
as properties, is constructed and sent back to the Server via WCF,
- the command handler can now retrieve the customer via
DeleteContactCommand.CustomerID from the ISession,
- and here is my question: How do I get a hold of the contact in order
to be able to call Customer.Contacts.Remove(Contact)? I have the
contacts ID in DeleteContactCommand.ContactID, but it isn't very
useful.

I can't iterate through Customer.Contacts and check the ID because a
Contact doesn't know about the ID (and I would like to keep it
persistence ignorant). I don't want to iterate through
Customer.Contacts and check the Name, Telephone, EMail, etc.
properties for equality - that would mean I would need to inflate my
DeleteContactCommand with all those values.

Can I (do I need to) query for the Contact via HQL if all I have is
it's surrogate ID? How so? It's not mapped, so how can I retrieve it?
And if I do need to query via HQL, the following would happen:

- database SELECT for the retrieval of the contact I want to remove,
- database SELECT to initialize the customers contact collection,
- database DELETE to delete the contact.

Idbags are supposed to improve performance over simple bags. I am
certain they do if used correctly. I must be missing something
fundamental. What is the correct way to handle this - seemingly simple
- case? Help, please!!! :-)

Customer Mapping (only the Contacts part):
...
<idbag name="Contacts" lazy="true" table="Contact">
      <collection-id type="Int32" column="ID">
          <generator class="DSDomain.Base.GeneralIDGenerator,
DSDomain" />
      </collection-id>
      <key column="Customer_ID"/>
      <composite-element class="Contact">
          <property name="Name" access="nosetter.pascalcase-
underscore" column="Name"/>
          <property name="Telephone" access="nosetter.pascalcase-
underscore" column="Telephone"/>
          <property name="Mobile" access="nosetter.pascalcase-
underscore" column="Mobile"/>
          <property name="EMail" access="nosetter.pascalcase-
underscore" column="EMail"/>
          <property name="Comment" access="nosetter.pascalcase-
underscore" column="Comment"/>
      </composite-element>
 </idbag>
...

thank you for your help,
Ramin

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