views:

155

answers:

1

I'm attempting to implement a PreInsertEvent listener using the latest version of NHibernate. One of the things I want to do with in this listener is find the database table that my entity is going to be mapped too. (Assuming that it is only one table).

Does anyone know where in the IEntityPersister I might be able to find this?

A: 

The answer to this is on the PreInsertEvent. Persister.PropertySpaces

public bool OnPreInsert(PreInsertEvent evt) {  
  for (var i = 0; i < evt.Persister.PropertySpaces.Length; i++)
  {
    Console.Out.WriteLine("\tevt.Persister.PropertySpaces = {0}", evt.Persister.PropertySpaces[i]);
  }
}

From the code base:
// Returns an array of objects that identify spaces in which properties of
// this entity are persisted, for instances of this class only.
// For most implementations, this returns the complete set of table names
// to which instances of the mapped entity are persisted (not accounting
// for superclass entity mappings).

MisterHux
Do you know you can accept your own answer? If you do this, it will not only get your accept rate up, but let everyone else know that you've answered the question and they don't need to respond.
Kendrick