Loquacious Nhibernate和composedID外键

时间:2012-04-24 17:51:46

标签: nhibernate

我有两个类,我试图在Loquacious Nhibernate中映射。

映射如下所示

  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])

我不确定我做错了什么,它看起来应该有效,但是我现在已经在这一段时间里一直在敲我的头并没有到达任何地方。关于我做错了什么想法?

2 个答案:

答案 0 :(得分:2)

最后想出了这个,发布给其他任何人。

我的问题是误解了map mapper。它应该是以下内容:

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

这解决了这个问题。当我看到功能签名时应该注意到它,但我完全错过了它。

答案 1 :(得分:0)

还有另一种更短的方式

ManyToOne(x => x.Foo, m => m.Columns(c=> c.Name("SomeIntID"),c => c.Name("SomeReferenceID")));