Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's ask different question: what if your application should present categories in <strong>tree-view</strong> control, which upon expanding category node will list all products? When you want to display all products there's no other way than ... actually querying database and loading all products.</p> <p>That's actually pretty common real-life scenario and one of easiest approaches is indeed to simply have <code>Category.Products</code> property. Of course there's nothing wrong with having such property, but the real question is how you should manage those objects.</p> <p>Luckily, you don't have to pull all the products with single category pull. <code>Category.Products</code> can be marked to <em>load lazily</em> (as opposed to <em>eagerly</em>, more information can be found <a href="http://nhforge.org/wikis/howtonh/lazy-loading-eager-loading.aspx" rel="nofollow">here</a>). What this means is, loading category won't query database for its products. Instead, NHibernate will create <em><a href="http://en.wikipedia.org/wiki/Proxy_pattern" rel="nofollow">proxy</a> object</em> for <code>Products</code>, which can be initialized later - when they are actually needed (think user expanding category node).</p> <hr> <p>And to answer your question...</p> <p>If single product is bound to <em>exactly one</em> category, then it's good real-life one-to-many relation example. However, if product can be described by more than one category, it's <strong>many-to-many</strong> relation then.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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