[NHibernate] Association mappings

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.