1

I have the following model:

public class SomeObject1 {
  public virtual Guid Id {get; set; }
  public string Property1 {get; set; }
}
public class SomeObject2 {
  public virtual Guid Id {get; set; }
  public string Property2 {get; set;}
}

and the table

SOME_OBJECTS 
  PK_SOME_OBJECTS Guid
  WHICH_OBJECT Integer
  PROPERTY1 varchar2
  PROPERTY2 varchar2

when the WHICH_OBJECT column = 1 the row contains information for SomeObject1, when the WHICH_OBJECT column = 2 the row contains information for SomeObject2.

How would I go about doing these mappings? I've found the discriminator feature but it seems to only apply when you have subclasses in an inheritance hierarchy.

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • 80%-duplicate of https://stackoverflow.com/questions/5831264/how-to-mapping-nhibernate-multiple-classes-with-different-business-logic-from – quetzalcoatl Mar 16 '18 at 13:37

1 Answers1

0

I'm pretty sure it's not possible to map two unrelated entities to the same table; however, you may be able to map them to two different views that reference the same table.

DanP
  • 6,310
  • 4
  • 40
  • 68
  • If you want absolutely zero relation, then probably not possible. But if all unrelated classes can be changed to implement common empty marker interface then it's totally possible to map then to a single table: https://stackoverflow.com/questions/5831264/how-to-mapping-nhibernate-multiple-classes-with-different-business-logic-from – quetzalcoatl Mar 16 '18 at 13:38