NHibernate fluent mapping

I'm working on a legacy system and have fluently introduced nHibernate, but have the latest mapping that doesn't seem to work.

code:

public class Permit
    {
    public int PermitId { get; set; }
    public char Discipline { get; set; }
    public PermitDetails PermitDetails { get; set; }
    }

public PermitDetails
    {
    public int PermitId { get; set; }
    }

public class GasPermitDetails : PermitDetails
    {
       ... permit details
    }

public class ElectricalPermitDetails : PermitDetails
    {
       ... permit details
    }

      

Scheme:

*tblPermit*
PermitId, int
Discipline, char
.... some other columns

*tblGas*
PermitId, int
....gasDetails

*tblElectrical*
PermitId, int
....electrical details

      

If tblPermit.Discipline

- "G"

, we need to get data from tblGas

. If tblPermit.Discipline

"E"

, we need to get data from tblElectrical

. I've been messing around trying to figure this out, but no luck so far.

+1


source to share


2 answers


It seems to me that the diagram appeared correctly. You may need a more specific issue with your problem, because I believe the PermitId for all subclasses of PermitDetails becomes foreign keys for the respective relationship tables.

Eg. for the discipline "gas", the corresponding permit must contain information about the gas for the permit. It is relevant if the PermitID in tblGas is a foreign key to the tblPermit id. Like this:

+---------------+         +----------------------+
|               | 1     1 |                      |
|   tblPermit   |<------->| tblGas               |
|               |         | (for gas discipline) |
|               |         |                      |
+---------------+         +----------------------+
|               |         |                      |
| {PK} PermitId |         | {FK} PermitID        | <- ForeignKey to tblPermit.PermitID
|               |         |                      |
+---------------+         +----------------------+

      



You don't need the Discipline column to select the correct data. You only need one request that looks tblElectrical, tblGas for the permission id. So you get your permission along with this information in this way.

(PS. Excuse me for using UML class diagram to render database tables, but kicked note notation doesn't translate well to ASCII)

0


source


(if tblPermit.Discipline is "G", we need to get data from tblGas. If tblPermit.Discipline is "E", we need to get data from tblElectrical). I've been messing around trying to get this figured out, but no luck so far.



The discriminator field is irrelevant since the PK fields of the subtypes are the FKs in their supertype table. Thus, it is a mapping of tables into subtypes.

0


source







All Articles