﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on NHibernate one-to-one</title><description>Dear Captain,
  
It is fairly rare case, and there are other ways to deal with that.
  
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment6</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment6</guid><pubDate>Wed, 20 Jun 2007 19:13:30 GMT</pubDate></item><item><title>CaptainPrivacyOfPrivacyBrigadee commented on NHibernate one-to-one</title><description>"At that point, it is more efficent to just grab all the data from the table rather than just the id."
  
  
I'm not sure I agree with this statement.  In fact, if the corresponding table row has many very large text or binary columns, how can it ever be more efficient to fetch the whole row as opposed to just fetching the id?
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment5</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment5</guid><pubDate>Wed, 20 Jun 2007 19:06:38 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate one-to-one</title><description>Okay, but changing them both to one-to-one (which the User.Blog one being Constrained=true) result in :
  
NHibernate: SELECT user0_.Id as Id1_1_, user0_.Name as Name1_1_, blog1_.Id as Id0_0_, blog1_.Name as Name0_0_ FROM Users user0_ inner join Blog blog1_ on user0_.Id=blog1_.Id WHERE user0_.Id=@p0; @p0 = '1'
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment4</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment4</guid><pubDate>Fri, 11 May 2007 07:14:08 GMT</pubDate></item><item><title>Sergey Koshcheyev commented on NHibernate one-to-one</title><description>And this is of course wrong, since &lt;one-to-one&gt; in general should be matched by a &lt;one-to-one&gt; on the other side since one-to-one means PK to PK association. There are exceptions of course, but your case is not one of them.
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment3</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment3</guid><pubDate>Fri, 11 May 2007 07:03:21 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate one-to-one</title><description>[BelongsTo] translate to &lt;many-to-one&gt;
  
  
When specifying constrained = true, I get this, better than outer join, but not what I would expect:
  
  
NHibernate: SELECT user0_.Id as Id1_1_, user0_.Name as Name1_1_, blog1_.Id as Id0_0_, blog1_.Name as Name0_0_, blog1_.[User] as User3_0_0_ FROM Users user0_ inner join Blog blog1_ on user0_.Id=blog1_.Id WHERE user0_.Id=@p0; @p0 = '1'
  
  
For reference, here is the NH mapping that it generates:
  
  
&lt;class name="ConsoleApplication1.Blog, ConsoleApplication1" table="Blog" lazy="true"&gt;
  
    &lt;id name="Id" access="property" column="Id" type="Int32" unsaved-value="0"&gt;
  
      &lt;generator class="native"&gt;
  
      &lt;/generator&gt;
  
    &lt;/id&gt;
  
    &lt;property name="Name" access="property" type="String"&gt;
  
      &lt;column name="Name"/&gt;
  
    &lt;/property&gt;
  
    &lt;many-to-one name="User" access="property" class="ConsoleApplication1.User, ConsoleApplication1" column="`User`" /&gt;
  
  &lt;/class&gt;
  
   &lt;class name="ConsoleApplication1.User, ConsoleApplication1" table="Users" lazy="true"&gt;
  
    &lt;id name="Id" access="property" column="Id" type="Int32" unsaved-value="0"&gt;
  
      &lt;generator class="native"&gt;
  
      &lt;/generator&gt;
  
    &lt;/id&gt;
  
    &lt;property name="Name" access="property" type="String"&gt;
  
      &lt;column name="Name"/&gt;
  
    &lt;/property&gt;
  
    &lt;one-to-one name="Blog" access="property" class="ConsoleApplication1.Blog, ConsoleApplication1" constrained="true" /&gt;
  
  &lt;/class&gt;
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment2</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment2</guid><pubDate>Thu, 10 May 2007 22:08:29 GMT</pubDate></item><item><title>Sergey Koshcheyev commented on NHibernate one-to-one</title><description>One-to-one can be lazily loaded if you promise NHibernate that the other side of the relationship always exists, this is done by specifying constrained="true".
  
  
The two outer joins look like a bug to me, but I don't know what ActiveRecord does for [BelongsTo]. If both classes had a &lt;one-to-one&gt; mapping, there should only be one outer join.
</description><link>http://ayende.com/2381/nhibernate-one-to-one#comment1</link><guid>http://ayende.com/2381/nhibernate-one-to-one#comment1</guid><pubDate>Thu, 10 May 2007 21:31:53 GMT</pubDate></item></channel></rss>