1

我有两个类,我试图在 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])

我不确定我做错了什么,看起来它应该可以工作,但我一直在努力解决这个问题,但没有得到任何结果。关于我做错了什么的任何想法?

4

2 回答 2

2

终于想通了,把这个贴出来给其他来的人。

我的问题是误解了列映射器。它应该是以下内容:

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

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

于 2012-04-28T01:52:44.057 回答
0

还有另一种更短的方式

ManyToOne(x => x.Foo, m => m.Columns(c=> c.Name("SomeIntID"),c => c.Name("SomeReferenceID")));
于 2018-06-11T10:04:04.913 回答