Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just can talk about NHibernate. There you need a field for the primary key, it's up to you if you take business data (not recommended) or a surrogate key with no business meaning.</p> <p>Typical scenarios are:</p> <ul> <li>auto-incrementing value generated by the database</li> <li>guid generated by NHibernate</li> <li>guid generated by the business logic</li> </ul> <p><strong>There is a big advantage to have a unique id.</strong> When you pass your object around, for instance to the client and back to the server, you can't rely on memory identity. You could even have several instances in memory of the same business instance. The business instance is identified by the id.</p> <p><strong>Id-based comparison</strong> is a matter of taste. Personally I like simple and reliable code, and id-based comparison <em>is</em> simple and reliable, while <em>deep-comparison</em> is always a bit risky, error-prone, unmaintainable. So you end up with operator == comparing the memory identity and Equals comparing the business (and database) identity.</p> <p>NHibernate is the less intrusive way to map a class model to a relational database I know. In our large project we have primary keys and version properties (they are used for optimistic locking). You could argue that this is intrusive, because it is not used for the business logic.</p> <p><strong>NH doesn't require to have these properties.</strong> (however it needs one of the properties as primary key.) But consider:</p> <ul> <li>It just works better, eg. pessimistic locking is only possible with a appropriate property,</li> <li>faster: int id's perform better on many databases then other data types</li> <li>and easier: taking properties with a meaning to the business are discouraged for several reasons.</li> </ul> <p>So why making your life harder than necessary?</p> <hr> <p><strong>Edit:</strong> Just read <a href="http://nhforge.org/doc/nh/en/index.html#mapping-declaration-id" rel="nofollow noreferrer">the documentation</a> and found that NHibernate does <strong>not</strong> need an id property in the persistent class! If you don't have an indentifier, <a href="http://nhforge.org/doc/nh/en/index.html#persistent-classes-poco-identifier" rel="nofollow noreferrer">you can't use some features</a>. It is recommended to have it, it just makes your life easier.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload