简体   繁体   English

NHibernate-复合实体,由另一个实体映射的联接表

[英]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. 我有一个已经映射到表A的实体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. 对于实体B,我正在尝试进行合成,以便获得来自B的所有数据以及来自A的字段。尽管A的字段不应通过B进行更改,但它们仅用于用例。

I'm trying to build my (fluent) mapping for B like so: 我正在尝试为B构建(流利的)映射,如下所示:

  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. 它说表A已经存在。 Any ideas, or doesn't this work at all? 有什么想法,还是根本行不通?

Thanks 谢谢

This is a bad idea. 这是一个坏主意。 You should just reference A. 您应该只引用A。

If you don't want to change A from B's reference, just make it private and expose only getters for its properties. 如果您不想从B的引用中更改A,只需将其设为私有并仅公开其属性的吸气剂即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM