﻿<?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>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>Ok, thanks. Thinking on consequences...
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment31</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment31</guid><pubDate>Mon, 01 Feb 2010 18:45:35 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
To perform polymorphic query, yes
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment30</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment30</guid><pubDate>Mon, 01 Feb 2010 18:44:32 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>Thanks for a link - there is really a perfect example.
  
  
So just to confirm: does NHibernate always use way a) ?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment29</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment29</guid><pubDate>Mon, 01 Feb 2010 18:34:56 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Take a look here.
  
[ayende.com/.../...e-mapping-ndash-inheritance.aspx](http://ayende.com/Blog/archive/2009/04/10/nhibernate-mapping-ndash-inheritance.aspx)  
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment28</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment28</guid><pubDate>Mon, 01 Feb 2010 18:25:31 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>Now it's clear that your statement about session.Get was correct. I tried to find out what actually NHibernate does to load an instance mapped with "joined-subclass" strategy, and actually failed. I see two basic options here:
  
a) Do this using a single query involving all the tables in the hierarchy ( or b) a part of them, if entity type is partially known - e.g. as T generic argument of session.Get method)
  
c) Query for hierarchy root type, detect actual entity type and run a precise query involving just necessary tables.
  
  
So what algorithm is used by NHibernate in this case? A, b, c, a combination of some of them, etc.?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment27</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment27</guid><pubDate>Mon, 01 Feb 2010 18:23:40 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
Get does NOT return a proxy.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment26</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment26</guid><pubDate>Mon, 01 Feb 2010 17:41:46 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>&gt; (i.e. won't be able to successfully cast it to e.g. Dog). 
  
  
I mean "I won't be able to ..."
  
  
&gt; The query that would run in this case fetches just Dog's fields
  
  
Sorry, "Pet's fields."
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment25</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment25</guid><pubDate>Mon, 01 Feb 2010 17:18:00 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>If I understand everything correctly, earlier session.Get[Pet](id) would return a proxy, which type isn't dependent on actual Pet type there (i.e. won't be able to successfully cast it to e.g. Dog). 
  
  
The query that would run in this case fetches just Dog's fields, so this line must lead either to DB interaction, or to unexpected result:
  
double barkVolume = dog.BarkVolume; // Any DB interaction?
  
  
But since you describe new functionality, it's desirable to describe what's changed in this case.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment24</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment24</guid><pubDate>Mon, 01 Feb 2010 17:01:14 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
Similar to what would happen if I did:
  
  
session.Get[Pet](id)
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment23</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment23</guid><pubDate>Mon, 01 Feb 2010 16:50:27 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>&gt; person.Pet - db query
  
  
Which tables will be used by this query in described case?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment22</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment22</guid><pubDate>Mon, 01 Feb 2010 16:46:14 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Ivos,
  
NHibernate still follows in Hibernate footsteps, but is not limited to them
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment21</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment21</guid><pubDate>Mon, 01 Feb 2010 08:16:56 GMT</pubDate></item><item><title>ivos commented on NHibernate new feature: No proxy associations</title><description>Nice! just a question: all these new proxy/lazy loafing new features are here because hibernate has them or just because they are really good? The proper question should be: is nhibernate still following hibernate's steps?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment20</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment20</guid><pubDate>Mon, 01 Feb 2010 05:13:39 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
  
var person - db query
  
person.Pet - db query.
  
That is all
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment19</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment19</guid><pubDate>Sun, 31 Jan 2010 12:19:01 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>Let's imagine we have Person.Pet reference of Animal type, and the instance it refers can actually be of type Cat, Dog, ... any other of its 20 inheritors (so the hierarchy is mapped to 20 different tables). And we use class per table inheritance mapping with type discriminator.
  
  
Let's think I run the following code:
  
  
var person = ...; // Person instance is loaded
  
var pet = person.Pet; // Animal instance is loaded, but in which part?
  
var dog = pet as Dog;
  
if (dog!=null) {
  
  double barkVolume = dog.BarkVolume; // Any DB interaction?
  
}
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment18</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment18</guid><pubDate>Sun, 31 Jan 2010 09:05:19 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>When you access the property on the root entity, we load the value (one query).
  
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment17</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment17</guid><pubDate>Sat, 30 Jan 2010 19:41:29 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>&gt; there are things that I do because people want it enough, not because I think it is good
  
  
Good answer ;)
  
  
&gt; If you access the property, there is no query.
  
  
So may be I'm missing something. While doing the first query, you actually don't know the exact type of referenced entity (of course, if there is inheritance hierarchy with type discriminator), and thus you don't know how to completely fetch the instance. 
  
  
Querying all the tables from the hierarchy is, likely, a bad idea as well, because there can be lots of them.
  
  
So how such case is handled?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment16</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment16</guid><pubDate>Sat, 30 Jan 2010 19:26:29 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
If you access the property, there is no query.
  
re: deeds, there are things that I do because people want it enough, not because I think it is good
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment15</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment15</guid><pubDate>Sat, 30 Jan 2010 12:00:18 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>&gt; when yo materialize a proxy
  
  
Sorry, wrong description, I mean "when NH resolves the reference".
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment14</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment14</guid><pubDate>Sat, 30 Jan 2010 11:56:42 GMT</pubDate></item><item><title>Alex Yakunin commented on NHibernate new feature: No proxy associations</title><description>Ah, yes... Surely there is a single query when yo materialize a proxy. But what happens if you access a property of inherited type later?
  
  
Concerning the reasoning - well, deeds say more than words.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment13</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment13</guid><pubDate>Sat, 30 Jan 2010 11:55:22 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Alex,
  
I still don't agree with your reasoning.
  
And it takes a single query.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment12</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment12</guid><pubDate>Fri, 29 Jan 2010 08:14:14 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Martin,
  
Again, no. Use it if you need it, but I don't like needing it
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment11</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment11</guid><pubDate>Fri, 29 Jan 2010 08:13:46 GMT</pubDate></item><item><title>Martin Aatmaa commented on NHibernate new feature: No proxy associations</title><description>To rephrase Cassio Tavares' question:
  
  
Do you recommend to use it in all many-to-one _polymorphic_ associations?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment10</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment10</guid><pubDate>Fri, 29 Jan 2010 06:42:13 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Gamlor,
  
In general, all properties/methods must be virtual.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment9</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment9</guid><pubDate>Thu, 28 Jan 2010 16:36:42 GMT</pubDate></item><item><title>Gamlor commented on NHibernate new feature: No proxy associations</title><description>Just out of curiosity (I'm not a NHibernate-user). The Comment.Post-property has to be virtual in order to allow this behaviour, right? 
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment8</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment8</guid><pubDate>Thu, 28 Jan 2010 16:11:35 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Steve,
  
That implies eager loading, the same cost is associated with this or with eager loading.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment7</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment7</guid><pubDate>Thu, 28 Jan 2010 15:26:09 GMT</pubDate></item><item><title>Steve Degosserie commented on NHibernate new feature: No proxy associations</title><description>I mean, NH could automatically pre-load to the entity type of lazy many-to-one association.
  
If I do a comparison 'comment.Post.Id == 123', you know it better than me, Post is not going to be lazy-loaded because the proxy holds the Id. Similarly, I would expect lazy-loading not to be triggered if I do 'comment.Post is Article'.
  
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment6</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment6</guid><pubDate>Thu, 28 Jan 2010 15:17:29 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>Steve,
  
You _can_ do that if you want to eager load.
  
But in some cases, you _want_ to do things lazily.
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment5</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment5</guid><pubDate>Thu, 28 Jan 2010 15:07:53 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate new feature: No proxy associations</title><description>No, I don't.
  
If you can, keep the current behavior. This requires NH to do more work and it encourage bad design practices
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment4</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment4</guid><pubDate>Thu, 28 Jan 2010 15:07:25 GMT</pubDate></item><item><title>Steve Degosserie commented on NHibernate new feature: No proxy associations</title><description>Why not load the type of the associated object during the initial query (might need to add some joins depending on the inheritance storage strategy chosen) so that a proxy of the correct type can be generated ?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment3</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment3</guid><pubDate>Thu, 28 Jan 2010 14:56:53 GMT</pubDate></item><item><title>Cassio Tavares commented on NHibernate new feature: No proxy associations</title><description>Really Great, but do you recommend use it in all many-to-one associations? Is there a rule?
</description><link>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment2</link><guid>http://ayende.com/4378/nhibernate-new-feature-no-proxy-associations#comment2</guid><pubDate>Thu, 28 Jan 2010 14:38:32 GMT</pubDate></item></channel></rss>