views:

1322

answers:

1

Let's say I have an existing database with the following 3 tables:

Table1:
(PK)T1ID1
(PK)T1ID2

Table2:
(PK)T2ID1

Table3:
(FK)T1ID1
(FK)T1ID2
(FK)T2ID1 (Where the 3 keys come from the tables above)

My question is: How do I map Table3 with Fluent NHibernate?
What is confusing to me is what to do about the fact that its composite keys come from 2 different tables.

I have the following for the mappings for tables 1 and 2:

public class Table1
{
    public virtual long T1ID1 { get; set; }
    public virtual long T1ID2 { get; set; }
}

public class Table2
{
    public virtual long T2ID1 { get; set; }
}

public class Table1Map
{
    public Table1Map()
    {
        Table("Table1");

        CompositeId()
            .KeyProperty(x => x.T1ID1, "T1ID1")
            .KeyProperty(x => x.T1ID2, "T1ID2");
    }
}

public class Table2Map
{
    public Table2Map()
    {
        Table("Table2");

        Id(x => x.T2ID1, "T2ID1");
    }
}
A: 

try looking at http://stackoverflow.com/questions/1581418/fluent-nhibernate-and-composite-id-with-single-column-name I think what you're after is the ".KeyReference()" property. The link above is using an old version of FNH but all you need to be concerned with , with regards to your issue is that the method names are slightly different. all the rest of that article should help you.

Let me know how you go.

cdmdotnet