2009/8/3 William Chang <[email protected]>

>
> All my previous projects the key was assigned by the database, but
> this new project I'm implementing today's best techniques (e.g.
> GuidComb) and using ORM (e.g. ActiveRecord).
>
DB-assigned IDs are not the spawn of the devil. They just don't match the
unit-of-work-model that NH/AR uses. Guid.comb is a good compromise. NH can
create one and in the case of a manual insert, the DB also knows how to
create a new ID.


> I created the TransactionGroupUser object explicitly. Is this the
> right approach of handling multiple collections (e.g. IList) for the
> association table with surrogate key? Source code snippet below:

There is no right or wrong approach. You can even has both in the same
model. I have this situation in one of my models:

Customer 1-* ServiceSubscription *-1 Service

Essentially it is an n-m-association between Customer and Service. The
ServiceSubscription has other attributes as well, for example an association
(FK) to negotiated SLA and price and of course a surrogate ID. However, I
have a lot of internal customers (other divisions) that are never invoiced.
For those I just have to see who uses which service, so it boils down to:

Customer *-* Service

In the end, I use both in my persistence model. Customer has an
ICollection<Service> that I mapped as HasAndBelongsToMany, which is
populated from the ServiceSubscription table. Also I have an
ICollection<ServiceSubscription> which is a HasMany-mapped property.

This works as a charm, but for using the ServiceSubscription-table as an
association-table for the n-m-association, I had to ensure that all other
columns than the keys to Customer and Service are nullable or defaultable.
In the case of the ID, this is a DB-generated key.

BTW, if your are going for best practice, don't expose bidirectional
associations. Have virtual protected collections and expose an IEnumerable
along with AddXXX() and RemoveXXX() methods. This is the only way to ensure
that both ends have the same information at any time.

-Markus

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to