NHibernate, непосредственное отображение, каскадная вставка

Я думаю, что у GA есть прямой способ сделать это? Смотрите скриншот. Вы искали что-то еще?

enter image description here

5
задан 3 May 2009 в 19:21
поделиться

2 ответа

Set the cascade attribute of the one-to-one in the Company mapping.

But, on another note: Have you thought of mapping the CompanySettings as a 'component' of Company instead of a separate entity ?

Isn't it so that 'CompanySettings' is a 'value object', and should be mapped better as a component ?

By doing this, you can put the CompanySettings values in the same table as 'Company', but it will be treated as a separate class.

Since this is a one-to-one mapping, I think it is a better option for your data model as well.

Then, your mapping would look something like this:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"`>
  <class name="AST.Domain.Company, AST.Domain" table="Companies">
    <id name="EntityID" column="CompanyId">
      <generator class="guid.comb" />
    </id>
    <property name="CompanyName" />
    . . .
    <component name="Settings" class="AST.Domain.CompanySettings, AST.Domain">
        <property name="MaxUsers" />
    </component>
  </class>
</hibernate-mapping>

You will have indeed 2 separate objects (Company & CompanySettings, and Company will have a 'Companysettings' object, but the settings will be saved in the Company table).

Or, is there any special reason on why you've put the CompanySettings in a separate table ? I mean, it is a one-to-one relation so this is completely not necessary (and imho even a bad practice :) ).

2
ответ дан 14 December 2019 в 08:59
поделиться

Have you tried specifying cascade="all" on your one-to-one mapping?

5
ответ дан 14 December 2019 в 08:59
поделиться
Другие вопросы по тегам:

Похожие вопросы: