2012-04-24 66 views
1

我有兩個類,我試圖在Loquacious Nhibernate中映射。Loquacious Nhibernate和collabID外鍵

的映射是類似下面的

public class FooMap : ClassMapping<Foo> 
    { 
    Table("FooTableName"); 
    ComposedId(compIDMapper => 
     { 
     compIDMapper.Property(x => x.SomeInt, m => m.Column("SomeInt")); 
     compIDMapper.ManyToOne(x => x.SomeReference, m => m.Column("SomeReference")); 
     }); 
    } 

    public class BarMap : ClassMapping<Bar> 
    { 
    Table("BarTableName"); 
    Id(x => x.ID, m => m.Column("barID")); 

    ManyToOne(x => x.Foo, m => m.Columns(columnMapper => 
                  { 
                   columnMapper.Name("SomeIntID"); //Both of these columns are in the BarTableName like they should be 
                   columnMapper.Name("SomeReferenceID"); 
                  })); 
    } 

但正在興建中的映射,當我得到以下錯誤:

Foreign key (FK554EAF2427B2CA28:BarTableName[SomeIntID])) must have same number of columns as the refe,renced primary key (FooTableName[SomeInt, SomeReference]) 

我不知道我在做什麼錯了,看起來應該可以工作,但是我現在一直在嘲弄我的頭,並且沒有到任何地方。關於我在做什麼的任何想法都是錯誤的?

回答

1

終於明白了這一點,發佈給任何其他人。

我的問題是誤解列映射器。它應該是以下內容:

ManyToOne(x => x.Foo, m => m.Columns(new Action<IColumnMapper>[] 
                   { 
                    colMapper => colMapper.Name("SomeIntID"), 
                    colMapper => colMapper.Name("SomeReferenceID") 
                   })); 

這解決了這個問題。當我看着函數簽名時應該注意到它,但我完全錯過了它。