Series Articles
[Nhibernate] Architecture
[NHibernate] Isessionfactory Configuration
[NHibernate] Persistence class (persistent Classes)
[NHibernate] O/R Mapping Basics
[NHibernate] Collection Class (collections) mappings
Introduction
One-way correlation is the most common and most difficult to use correctly. In this article, we will go through the canonical case, starting with one-way mapping and then involving two-way cases. We will use person and address in all the examples. The examples do not include namespaces and assemblies, and we focus on important aspects.
We classify associations by whether to use table joins and diversity (unidirectional or bidirectional).
It is not applicable to allow null foreign keys in the traditional data model, so our example does not use a foreign key that is allowed to be empty, which is not required in nhibernate, and if you remove the control constraint, the mapping will work as usual.
One-Way Association
Multi-pair (many to one)
One-to-one (one to one)
One-to-many (one to many)
One-way association using table joins
Multi-pair (many to one)
One-to-one (one to one)
One-to-many (one to many)
Many-to-many (many to many)
Bidirectional correlation
One to many/multi-pair (many to a)
A two-way, one to many association is a common type of association. (This is the standard parent/child relationship)
1 <classname= "Person">2 <IDname= "Id"column= "PersonId">3 <Generatorclass= "Native" />4 </ID>5 <Many-to-onename= "Address"6 column= "Addressid"7 Not-null= "true"8 />9 </class>Ten <classname= "Address"> One <IDname= "Id"column= "Addressid"> A <Generatorclass= "Native" /> - </ID> - <Setname= "People"Inverse= "true"> the <Keycolumn= "Addressid" /> - <One-to-manyclass= "Person" /> - </Set> - </class> + CREATE TABLE person - ( + personId bigint NOT null primary key, A addressid bigint NOT NULL at ) - CREATE TABLE Address - ( - addressid bigint NOT null primary key -)
One-to-one (one to one)
Two-way association using table joins
One to many/multi-pair (many to a)
One-to-one (one to one)
Many-to-many (many to many)
Summarize
There is a general understanding of the knowledge point, the specific application also need in the subsequent articles, through examples to illustrate.
This article is from "Nhibernat Chinese document"