Hi, I'm new to NHibernate and have some general Questions about
mapping of class hierarchies. I'm using mapping attributes.

I have a self-referencing base-class. I tried this:

[Class(NameType = typeof(BaseClass), Table = "BASE")]
public abstract class BaseClass
{
  [Id(0, Name = "Id", Column = "ID")]
  [Generator(1, Class = "hilo")]
  public virtual long Id { get; set; }

  [ManyToOne(Column = "PARENT_ID", ForeignKey = "FK_BASE_PARENT")]
  public virtual BaseClass Parent { get; set; }
}

My intention was to inherit some classes of this BaseClass so that
they all are self-referencing without to reprogramm it in every
instance of my classes.

I Know that this doesn't work (NHibernate throws an exception) because
the type of the Parent-property is by design wrong (BaseClass is
abstract and can never be load).

So I tried this:

[Class(NameType = typeof(BaseClass), Table = "BASE")]
public abstract class BaseClass
{
  [Id(0, Name = "Id", Column = "ID")]
  [Generator(1, Class = "hilo")]
  public virtual long Id { get; set; }

  [Property(Column = "PARENT_ID")]
  public virtual long ParentId { get; set; }
}

... with of course worked. But now I have no foreigh-key to myselfe.
Is there a way to generate a foreign-key?

Who can help me?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to