Foreign key part of unique constraint or primary key
Hi,
is it possible to include the foreign-key which is created for an many-to-one mapping in an index/unique constraint with a fluent mapping?
I have something like the following:
class Document
{
Guid Id;
public virtual IList<DocumentRevision> Revisions { get; private set; }
}
class DocumentRevision
{
Guid document_id;
int revision;
}
Is it possible to have a primary key for the document revision table which consists of document_id and revision, since a given revision must only exist a single time for each document. Also a combined index should be beneficial because most querys would be like give me the latest revision of a given document.
But I haven't found a way to create a mapping for this.
Thanks
2 Posted by rkevinstout on 25 May, 2010 08:58 PM
This can be accomplished by using a CompositeId. For example:
Good luck,
Kevin Stout
3 Posted by Fionn on 25 May, 2010 09:47 PM
Would it also be possible if not specifying the foreign key as Guid but as class reference, like with this classes:
Thanks
4 Posted by rkevinstout on 25 May, 2010 10:42 PM
Yes, you are correct.