开发者

NHibernate - Composite entity, joining table mapped by another entity

I have the following tables:

A
--
Id : int
SomeString : varchar(20)

B
--
Id : int
BString: nvarchar(10)
AId : int // FK to A

I have an entity A which is already mapped to the table A.

For the entity B, I'm trying to do a composite so that I have all the data from B, as well as the fields from A. The fields from A shouldn't be changable via B though, they're just there for the use case.

I'm trying to build my (fluent) mapping for B like so:

  Table("B");
  Join(
    "A"
    m =>
      {
        m.KeyColumn("AId");
        m.Inverse();
  开发者_运维知识库      m.Map(p => p.SomeString);
      }
  );
  Map(p => p.BString);

The problem occurs when I try to export the schema; it says the table A already exists. Any ideas, or doesn't this work at all?

Thanks


This is a bad idea. You should just reference A.

If you don't want to change A from B's reference, just make it private and expose only getters for its properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜