Object A
has a one-to-many association: many object B
.
When I look in the database -- TableB
-- I'd like to see the unique, readable string A.Name
instead of having always to join or subselect on a surrogate integer identifier to see the name.
I can map Name
as the identifier for A
, but this causes lots of extra SELECT
queries because NHibernate can't identify whether an instance of A
is transient or persistent.
I imagine that I could use a composite key, combining a native-assigned surrogate key with the natural key. This seems sub-optimal, but I'd love to hear some opinions.
What I'm really looking for is a strategy for using a single-column natural key while allowing NHibernate to identify transient instances.
- Is it possible?
- What is the mapping -- fluent or hbm?
On the other hand, if this is all a terrible idea and I should just rely on database views with subselects, please explain.
Thanks.