NHibernate, generics mapping with common interface – Education Career Blog

I’ve run into a nhibernate dilemma that I’m sure can be solved, cause I haven’t run into a problem yet that can’t be.
I have a couple of small classes:

class PropertyDataString : IPropertyData
  string Value {get; set;}
  void Render() { ..render string property.. }

class PropertyDataSelection : IPropertyData
  string Value {get; set;}
  void Render() { ..render selection property.. }

and the interface:

interface IPropertydata
  string Value { get; set; }
  void Render() {}

Now I have a parent class:

class Parent
  List<IProperty> Properties

The question how can I map this? As you see both PropertyDataString and PropertyDataSelection has the same properties only difference is in the interface implemented methods.

,

Chapter 8. Inheritance Mapping

In this case, I recommend the Table per class hierarchy strategy.

Leave a Comment