Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map a n-column primary key with nHibernate

I have a table with 2 columns as PK (composite primary key).

How can I map them to "Id" in hbm.xml?

<id name="A" />  

How can I do it with fluent nhibernate?

like image 608
Elad Benda Avatar asked Dec 02 '22 01:12

Elad Benda


1 Answers

The NHibernate documentation describes how to use and map a composite-id.

You can also use a component as compositeid.

And for Fluent NHibernate:

public class ClassNameMap: ClassMap<ClassName>
{
    public ClassNameMap()
    {
        CompositeId().
            .KeyReference(x => x.A, "A")
            .KeyReference(x => x.B, "B");
    }
}
like image 138
Gerard Avatar answered Dec 05 '22 05:12

Gerard