pencilCake
pencilCake

Reputation: 53243

What rules and conventions should a class follow to be able to work properly with NHibernate?

I am working on a code template to create POCOs from my Db Schema.

Is there a kind of summary list that defines the MUST-TO-HAVEs in a class so that it can be mapped to Db with NHibernate without any problem.

(As I know, one of the rules is to have your properties virtual so that NHibernate proxies can override)

Thanks!

Upvotes: 0

Views: 54

Answers (1)

Jaguar
Jaguar

Reputation: 5958

well, besides the virtual properties you must also:

  • have a parameter-less constructor, even if private/protected
  • have a property (or combination of properties) that identify an object (usually the primary key of the table)
  • override int GetHashCode() and bool Equals(object obj) by using the aforementioned object identifier in their body

Upvotes: 3

Related Questions