<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Must Everything Be Virtual With NHibernate, Part II</title>
	<atom:link href="http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Wed, 08 Sep 2010 21:03:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Must Everything Be Virtual With NHibernate, Part III &#124; The Inquisitive Coder &#8211; Davy Brion&#8217;s Blog</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22615</link>
		<dc:creator>Must Everything Be Virtual With NHibernate, Part III &#124; The Inquisitive Coder &#8211; Davy Brion&#8217;s Blog</dc:creator>
		<pubDate>Sun, 27 Sep 2009 17:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22615</guid>
		<description>[...] Must Everything Be Virtual With NHibernate, Part II [...]</description>
		<content:encoded><![CDATA[<p>[...] Must Everything Be Virtual With NHibernate, Part II [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22608</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Wed, 23 Sep 2009 20:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22608</guid>
		<description>Seems a slightly contrived example to me.
I can buy that to get lazy loading the properties would require them to be virtual. But why must methods also be virtual? I can see in your example that side stepping the property and accessing the field behind it will also side step the lazy loading.

My response... Don&#039;t do that then.

If you want lazy loaded properties then only use the properties. This is the same problem as when you have _any_ logic inside the getter/setter.

So, why does NH need access to the internals of my methods? What, exactly, does NH _do_ to the code? If I _always_ use properties and not fields, what is there extra for NH to do?</description>
		<content:encoded><![CDATA[<p>Seems a slightly contrived example to me.<br />
I can buy that to get lazy loading the properties would require them to be virtual. But why must methods also be virtual? I can see in your example that side stepping the property and accessing the field behind it will also side step the lazy loading.</p>
<p>My response&#8230; Don&#8217;t do that then.</p>
<p>If you want lazy loaded properties then only use the properties. This is the same problem as when you have _any_ logic inside the getter/setter.</p>
<p>So, why does NH need access to the internals of my methods? What, exactly, does NH _do_ to the code? If I _always_ use properties and not fields, what is there extra for NH to do?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: den Ben</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22607</link>
		<dc:creator>den Ben</dc:creator>
		<pubDate>Wed, 23 Sep 2009 18:13:47 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22607</guid>
		<description>Apart from Customer/customer -&gt; has to be Customer, as already stated in the comments.  There&#039;s still the &#039;Why do AddOrderLine and RemoveOrderLine need to be virtual&#039;?

Well, you kinda pointed out the solution in your _before_ link :)

They have to be virtual so the proxy generated by NHibernate can override them, adding some lazy loading mojo to it.</description>
		<content:encoded><![CDATA[<p>Apart from Customer/customer -&gt; has to be Customer, as already stated in the comments.  There&#8217;s still the &#8216;Why do AddOrderLine and RemoveOrderLine need to be virtual&#8217;?</p>
<p>Well, you kinda pointed out the solution in your _before_ link <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>They have to be virtual so the proxy generated by NHibernate can override them, adding some lazy loading mojo to it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: E</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22606</link>
		<dc:creator>E</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22606</guid>
		<description>Field-backed properties are useful when you want to make the variable static or readonly.  In this case, I agree that the auto-getter/setter makes the code more straightforward.</description>
		<content:encoded><![CDATA[<p>Field-backed properties are useful when you want to make the variable static or readonly.  In this case, I agree that the auto-getter/setter makes the code more straightforward.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: efdee</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22605</link>
		<dc:creator>efdee</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22605</guid>
		<description>This feels like a fabricated example, why are you using a field-backed property instead of the auto property? If the expectation is that your property is lazy-loaded then it should not necessarily come as a surprise that your field is not.

That doesn&#039;t mean it&#039;s not something that people would make mistakes against or that I don&#039;t agree to what you say :-)</description>
		<content:encoded><![CDATA[<p>This feels like a fabricated example, why are you using a field-backed property instead of the auto property? If the expectation is that your property is lazy-loaded then it should not necessarily come as a surprise that your field is not.</p>
<p>That doesn&#8217;t mean it&#8217;s not something that people would make mistakes against or that I don&#8217;t agree to what you say <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: E</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22604</link>
		<dc:creator>E</dc:creator>
		<pubDate>Wed, 23 Sep 2009 13:28:44 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22604</guid>
		<description>Customer is virtual (lazy loaded), customer is null until Customer is loaded.  customer.DiscountPercentage will return a null reference exception if Customer hasn&#039;t been loaded.  This is a good example of why static methods can prevent side-effects.</description>
		<content:encoded><![CDATA[<p>Customer is virtual (lazy loaded), customer is null until Customer is loaded.  customer.DiscountPercentage will return a null reference exception if Customer hasn&#8217;t been loaded.  This is a good example of why static methods can prevent side-effects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22603</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 23 Sep 2009 11:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22603</guid>
		<description>yeah, they need to be virtual... but why? what can go wrong if they aren&#039;t?</description>
		<content:encoded><![CDATA[<p>yeah, they need to be virtual&#8230; but why? what can go wrong if they aren&#8217;t?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22602</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Wed, 23 Sep 2009 10:25:31 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22602</guid>
		<description>I would say that the two methods (AddOrderLine and RemoveOrderLine) need to be virtual. Not sure why, but everytime I have one of these methods and I forget to put virtual around these, I get errors during Factory configuration. 

If I was to guess a reason it would be because of OrderLines is lazy loaded.</description>
		<content:encoded><![CDATA[<p>I would say that the two methods (AddOrderLine and RemoveOrderLine) need to be virtual. Not sure why, but everytime I have one of these methods and I forget to put virtual around these, I get errors during Factory configuration. </p>
<p>If I was to guess a reason it would be because of OrderLines is lazy loaded.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22601</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 23 Sep 2009 06:54:12 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22601</guid>
		<description>Yeah, you can also use interfaces to avoid virtual methods with NHibernate

the Date property should indeed be virtual, but that&#039;s not the actual problem that i&#039;m trying to show here

accessing the customer through the property instead of the field would indeed change everything ;)</description>
		<content:encoded><![CDATA[<p>Yeah, you can also use interfaces to avoid virtual methods with NHibernate</p>
<p>the Date property should indeed be virtual, but that&#8217;s not the actual problem that i&#8217;m trying to show here</p>
<p>accessing the customer through the property instead of the field would indeed change everything <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noam Gal</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-ii/comment-page-1/#comment-22600</link>
		<dc:creator>Noam Gal</dc:creator>
		<pubDate>Wed, 23 Sep 2009 06:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1634#comment-22600</guid>
		<description>The Date property must also be virtual, in case an Order is being lazy-loaded as a reference from a Customer or Employee. At run time the Customer/Employee will have a proxy at hand, and will need to initialize it whenever an attempt to get the Date is made.

I am not sure about this, but maybe we also need to access the customer using the property (Customer) and not the field directly.

Wouldn&#039;t working with interfaces all around (IOrder, ICustomer, IEmployee) make everything more transparent? The runtime proxy will implement the interface, instead of inheriting from the class, and the property calls will pass through it to the real object (after initialization) ? I remember using this method in Hibernate. Is it also available on NHibernate?</description>
		<content:encoded><![CDATA[<p>The Date property must also be virtual, in case an Order is being lazy-loaded as a reference from a Customer or Employee. At run time the Customer/Employee will have a proxy at hand, and will need to initialize it whenever an attempt to get the Date is made.</p>
<p>I am not sure about this, but maybe we also need to access the customer using the property (Customer) and not the field directly.</p>
<p>Wouldn&#8217;t working with interfaces all around (IOrder, ICustomer, IEmployee) make everything more transparent? The runtime proxy will implement the interface, instead of inheriting from the class, and the property calls will pass through it to the real object (after initialization) ? I remember using this method in Hibernate. Is it also available on NHibernate?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
