CompositeId().KeyProperty(x => x.Id).KeyProperty(x => x.Version);

Protip: Avoid composite Id's. Guessing by your version column, I'm assuming
that you want this Id in place so when you change your entity (update the
version in the business domain, say on a policy that has been changed or
something) you want any of the associated entities to be wiped (by nature of
the compositeId to the parent no longer being valid) and you want to put in
new values for your entity's associations (new credit cards for a policy, as
was discussed in another thread recently).

If you have control over the database, and this isn't a legacy db, then
there are other, more DDD/OO methods of performing this. A contract with an
entity NHibernate has for the Id states at the simplest level, that the Id
to an entity should never change, otherwise it's a different entity. What
you're going to now have to keep track of, is letting NHibernate know how to
manage the entityId changing every time a newer version of it is created,
and if it's the same object, you're going to have to flush your session and
2nd level cache all the time, rendering them fairly useless.

Just food for thought :)

On Wed, Jan 20, 2010 at 1:28 PM, Tonya <[email protected]> wrote:

> Hi,
>
> I have a table with a composite key that consists of Id and Version
> columns.  What is the syntax for using the CompositeId() method in a
> mapping?
>
> Thanks,
> Tonya
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" 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/fluent-nhibernate?hl=en.

Reply via email to