<?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: Querying With NHibernate</title> <atom:link href="http://davybrion.com/blog/2008/10/querying-with-nhibernate/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Wed, 08 Feb 2012 11:42:42 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Ian</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-42938</link> <dc:creator>Ian</dc:creator> <pubDate>Thu, 24 Jun 2010 13:20:49 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-42938</guid> <description>Cool example.  But what if we need more information out of the subqueries, and return fewer columns from customers?  For example, suppose we want to email the customers and tell them exactly which orders have a discontinued product on them?  For performance reasons we only need to return 4 fields from the database:  Customers.CustomerID, Customers.CompanyName, Customers.EmailAddress, Orders.OrderDate.  Now our orderIdsCriteria needs to return 2 fields: OrderID and OrderDate, which means that the customerIdsFromOrdersForProductCriteria can no longer use the orderIdsCriteria for its subquery Subqueries.PropertyIn(&quot;Id&quot;, orderIdsCriteria) since the detached criteria returns more than 1 field.Can you please explain how to do that?  My knowledge of nhibernate querying is very limited as of yet and this is something that I need to do.</description> <content:encoded><![CDATA[<p>Cool example.  But what if we need more information out of the subqueries, and return fewer columns from customers?  For example, suppose we want to email the customers and tell them exactly which orders have a discontinued product on them?  For performance reasons we only need to return 4 fields from the database:  Customers.CustomerID, Customers.CompanyName, Customers.EmailAddress, Orders.OrderDate.  Now our orderIdsCriteria needs to return 2 fields: OrderID and OrderDate, which means that the customerIdsFromOrdersForProductCriteria can no longer use the orderIdsCriteria for its subquery Subqueries.PropertyIn(&#8220;Id&#8221;, orderIdsCriteria) since the detached criteria returns more than 1 field.</p><p>Can you please explain how to do that?  My knowledge of nhibernate querying is very limited as of yet and this is something that I need to do.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-42038</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Tue, 15 Jun 2010 07:17:44 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-42038</guid> <description>DetachedCriteria.For(typeof(Trade))
.CreateAlias(&quot;Client&quot;, &quot;client&quot;, JoinType.InnerJoin)
.Add(Restrictions.Eq(&quot;client.Number&quot;, 1234))
.List();</description> <content:encoded><![CDATA[<p>DetachedCriteria.For(typeof(Trade))<br
/> .CreateAlias(&#8220;Client&#8221;, &#8220;client&#8221;, JoinType.InnerJoin)<br
/> .Add(Restrictions.Eq(&#8220;client.Number&#8221;, 1234))<br
/> .List();</p> ]]></content:encoded> </item> <item><title>By: Kunjan Modi</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-41985</link> <dc:creator>Kunjan Modi</dc:creator> <pubDate>Mon, 14 Jun 2010 21:28:58 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-41985</guid> <description>I have a scenario where I am performing a Trade search with DetachedCriteria for Trade. Every Trade has a Client and some search filters are on the Client for eg. Search all trades where Client.Number = 1234. Can someone please how would I produce a query like the following with Nhibernate Criteria?Select
ID, TradeID, ...... (only Trade columns)
From Trade
Where Trade.ClientID IN (Select ID From Client where Number = 1234)</description> <content:encoded><![CDATA[<p>I have a scenario where I am performing a Trade search with DetachedCriteria for Trade. Every Trade has a Client and some search filters are on the Client for eg. Search all trades where Client.Number = 1234. Can someone please how would I produce a query like the following with Nhibernate Criteria?</p><p>Select<br
/> ID, TradeID, &#8230;&#8230; (only Trade columns)<br
/> From Trade<br
/> Where Trade.ClientID IN (Select ID From Client where Number = 1234)</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3234</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Mon, 06 Oct 2008 07:08:50 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3234</guid> <description>heh, now this is interesting... one of our database specialists at work told me that subqueries were indeed not the best way to fetch the dataso we compared the performance of the query with the subqueries, compared to one that uses only joins (and some variations on that)in each case, the one with subqueries performed better :)i think it&#039;s because the resultset of the subqueries is in this case the same for each row in the main query.  if the subqueries where using values of the rows in the main query, the join approach would probably be a lot faster i think</description> <content:encoded><![CDATA[<p>heh, now this is interesting&#8230; one of our database specialists at work told me that subqueries were indeed not the best way to fetch the data</p><p>so we compared the performance of the query with the subqueries, compared to one that uses only joins (and some variations on that)</p><p>in each case, the one with subqueries performed better <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>i think it&#8217;s because the resultset of the subqueries is in this case the same for each row in the main query.  if the subqueries where using values of the rows in the main query, the join approach would probably be a lot faster i think</p> ]]></content:encoded> </item> <item><title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #194</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3233</link> <dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #194</dc:creator> <pubDate>Mon, 06 Oct 2008 07:05:46 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3233</guid> <description>[...] Querying With NHibernate - Davy Brion explores the construction of complex queries in NHibernate using the criteria API, including looking at creating sub queries, and compares the underlying SQL to a hand crafted original. [...]</description> <content:encoded><![CDATA[<p>[...] Querying With NHibernate &#8211; Davy Brion explores the construction of complex queries in NHibernate using the criteria API, including looking at creating sub queries, and compares the underlying SQL to a hand crafted original. [...]</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3195</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Sun, 05 Oct 2008 11:37:08 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3195</guid> <description>yeah, i&#039;d usually try to do it with joins instead of any subqueries as well. But as far as i know (and if someone can correct this, please do so) you can only join on associations that have been mapped with NHibernate. So joining on &#039;dynamically&#039; composed resultsets is something that is not possible, unless i&#039;m mistaken. Maybe someone else can shed more light on this :)Having said that, i&#039;d like to know which aproach is better: the joins or the subqueries. Theoritically speaking, i&#039;d think the join approach is better. But these days, you&#039;re never really sure how the DB is going to optimize the query when it&#039;s actually being executed so i wouldn&#039;t be surprised if the subquery approach turns out to be just as fast as the joined approach.</description> <content:encoded><![CDATA[<p>yeah, i&#8217;d usually try to do it with joins instead of any subqueries as well. But as far as i know (and if someone can correct this, please do so) you can only join on associations that have been mapped with NHibernate. So joining on &#8216;dynamically&#8217; composed resultsets is something that is not possible, unless i&#8217;m mistaken. Maybe someone else can shed more light on this <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Having said that, i&#8217;d like to know which aproach is better: the joins or the subqueries. Theoritically speaking, i&#8217;d think the join approach is better. But these days, you&#8217;re never really sure how the DB is going to optimize the query when it&#8217;s actually being executed so i wouldn&#8217;t be surprised if the subquery approach turns out to be just as fast as the joined approach.</p> ]]></content:encoded> </item> <item><title>By: disco stu</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3194</link> <dc:creator>disco stu</dc:creator> <pubDate>Sun, 05 Oct 2008 11:27:11 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3194</guid> <description>scratch that! =&gt; like this&lt;code&gt;select
customer.CustomerId,
customer.CompanyName,
customer.ContactName,
customer.ContactTitle,
customer.Address,
customer.City,
customer.Region,
customer.PostalCode,
customer.Country,
customer.Phone,
customer.Fax
from
Customers Customer
join (
select distinct
Orders.CustomerID
from
Orders
join [Order Details] on [Order Details].OrderID = Orders.OrderID
where
[Order Details].ProductID = 24) ProductCustomer on ProductCustomer.CustomerID = Customer.ID&lt;/code&gt;</description> <content:encoded><![CDATA[<p>scratch that! =&gt; like this</p><p><code>select<br
/> customer.CustomerId,<br
/> customer.CompanyName,<br
/> customer.ContactName,<br
/> customer.ContactTitle,<br
/> customer.Address,<br
/> customer.City,<br
/> customer.Region,<br
/> customer.PostalCode,<br
/> customer.Country,<br
/> customer.Phone,<br
/> customer.Fax<br
/> from<br
/> Customers Customer<br
/> join (<br
/> select distinct<br
/> Orders.CustomerID<br
/> from<br
/> Orders<br
/> join [Order Details] on [Order Details].OrderID = Orders.OrderID<br
/> where<br
/> [Order Details].ProductID = 24) ProductCustomer on ProductCustomer.CustomerID = Customer.ID</code></p> ]]></content:encoded> </item> <item><title>By: disco stu</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3193</link> <dc:creator>disco stu</dc:creator> <pubDate>Sun, 05 Oct 2008 11:25:47 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3193</guid> <description>Disco Stu would do it like this:
&lt;code&gt;select
customer.CustomerId,
customer.CompanyName,
customer.ContactName,
customer.ContactTitle,
customer.Address,
customer.City,
customer.Region,
customer.PostalCode,
customer.Country,
customer.Phone,
customer.Fax
from
Customers Customer
join (
select
Orders.CustomerID
from
Orders
join [Order Details] on [Order Details].OrderID = Orders.OrderID
where
[Order Details].ProductID = 24
group by
Orders.CustomerID) ProductCustomer on ProductCustomer.CustomerID = Customer.ID&lt;/code&gt;</description> <content:encoded><![CDATA[<p>Disco Stu would do it like this:<br
/> <code>select<br
/> customer.CustomerId,<br
/> customer.CompanyName,<br
/> customer.ContactName,<br
/> customer.ContactTitle,<br
/> customer.Address,<br
/> customer.City,<br
/> customer.Region,<br
/> customer.PostalCode,<br
/> customer.Country,<br
/> customer.Phone,<br
/> customer.Fax<br
/> from<br
/> Customers Customer<br
/> join (<br
/> select<br
/> Orders.CustomerID<br
/> from<br
/> Orders<br
/> join [Order Details] on [Order Details].OrderID = Orders.OrderID<br
/> where<br
/> [Order Details].ProductID = 24<br
/> group by<br
/> Orders.CustomerID) ProductCustomer on ProductCustomer.CustomerID = Customer.ID</code></p> ]]></content:encoded> </item> <item><title>By: Querying With NHibernate - NHibernate blog - NHibernate Forge</title><link>http://davybrion.com/blog/2008/10/querying-with-nhibernate/comment-page-1/#comment-3191</link> <dc:creator>Querying With NHibernate - NHibernate blog - NHibernate Forge</dc:creator> <pubDate>Sun, 05 Oct 2008 11:06:09 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=480#comment-3191</guid> <description>[...] NOTE: this was originally posted on my own blog [...]</description> <content:encoded><![CDATA[<p>[...] NOTE: this was originally posted on my own blog [...]</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/13 queries in 0.007 seconds using disk: basic
Object Caching 458/459 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-02-08 17:31:35 -->
