开发者

NHibernate - Composite entity, joining table mapped by another entity

开发者 https://www.devze.com 2023-01-11 04:11 出处:网络
I have the following tables: A -- Id : int SomeString : varchar(20) B -- Id : int BString: nvarchar(10) AId : int // FK to A

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

精彩评论

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