Mapping multiple discriminator values to single default class in NHibernate

I have an existing RoleType table with data. I am trying to map this table in NHibernate using Table per class hierarchy:



  
    
  

      

  
  

  
  
  

Here, IRoleType is an interface, with implementors RoleA, RoleB and RoleC. This works. But here's the problem -

The table contains rows with "extra" discriminator values (2,3,5,6) that are not mapped to a persistent class. These values are deprecated in the domain, so its not useful to create persistent class for each. But we also cannot delete them from the database.

Is there a way to map these extra rows to a single "default" class? If not, how else can I solve this problem?

Thanks!

9
задан Guillermo Gutiérrez 11 June 2013 в 20:10
поделиться

1 ответ

Вы можете сделать это, сопоставив эти значения с одним. Пример:

<discriminator
    formula="case when RoleID in (2,3,5,6) then 0 else RoleId end" />    
<subclass name="RoleA" discriminator-value="1" />
<subclass name="RoleB" discriminator-value="4" />
<subclass name="RoleC" discriminator-value="7" />
<subclass name="DefaultRole" discriminator-value="0" />
19
ответ дан 4 December 2019 в 11:03
поделиться
Другие вопросы по тегам:

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