<?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: Summer of NHibernate Session 02a: Exploring Query Methods and Syntaxes (con&#8217;t) Screencast is Available</title>
	<atom:link href="http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/feed/" rel="self" type="application/rss+xml" />
	<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/</link>
	<description>Miscellaneous musings on life, .NET development, and related things that don't really matter</description>
	<pubDate>Thu, 17 May 2012 21:08:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Casque Dre</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-59/#comment-126315</link>
		<dc:creator>Casque Dre</dc:creator>
		<pubDate>Wed, 07 Mar 2012 03:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-126315</guid>
		<description>the sample back to earth.</description>
		<content:encoded><![CDATA[<p>the sample back to earth.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sbohlen</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-49375</link>
		<dc:creator>sbohlen</dc:creator>
		<pubDate>Tue, 09 Nov 2010 01:02:47 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-49375</guid>
		<description>@Adam:

What version of NH are you using?  Are you using NH 1.2 (as in the sample code downloads and the screencasts)?

In NH 2.1x and later the NHibernate.Expressions namespace was renamed to NHibernate.Restrictions to better correlate with the structure of the Java Hibernate codebase.  See if that helps and let me know~!

-Steve B.</description>
		<content:encoded><![CDATA[<p>@Adam:</p>
<p>What version of NH are you using?  Are you using NH 1.2 (as in the sample code downloads and the screencasts)?</p>
<p>In NH 2.1x and later the NHibernate.Expressions namespace was renamed to NHibernate.Restrictions to better correlate with the structure of the Java Hibernate codebase.  See if that helps and let me know~!</p>
<p>-Steve B.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-49337</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Mon, 08 Nov 2010 12:52:37 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-49337</guid>
		<description>I have no Projections library. Did I miss something during this screencast?
I tried to add using NHibernate.Expressions.Projections directive but it seems that there is no Expressions either.</description>
		<content:encoded><![CDATA[<p>I have no Projections library. Did I miss something during this screencast?<br />
I tried to add using NHibernate.Expressions.Projections directive but it seems that there is no Expressions either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: La Martina</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-32654</link>
		<dc:creator>La Martina</dc:creator>
		<pubDate>Sat, 22 May 2010 22:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-32654</guid>
		<description>Where is the example of using the Criteria API to get a strongly typed collection from a GROUP BY type SQL query? I have been unable to find an example of this and the NHibernate documentation is extremely vague.</description>
		<content:encoded><![CDATA[<p>Where is the example of using the Criteria API to get a strongly typed collection from a GROUP BY type SQL query? I have been unable to find an example of this and the NHibernate documentation is extremely vague.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sbohlen</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-25348</link>
		<dc:creator>sbohlen</dc:creator>
		<pubDate>Wed, 16 Dec 2009 17:40:09 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-25348</guid>
		<description>@Seth:

Great question; those are (obviously) very real concerns.  Later on in subsequent sessions you will begin to see how I leverage a testing support framework called NDbUnit to permit my tests to properly manage state, ensure that expected records are present in the DB before the test, and cleans up after the tests.

I don't generally like using DB transaction rollbacks as my method of reverting DB state after tests run b/c there are so many things that can go wrong w that strategy (especially if/when part of the DB methods you might be testing makes use of transactions internally and would need to be aware of outer transaction scope, etc. to properly enlist in the right transaction, etc.).

NDbUnit places this responsibility in a tooling framework that doesn't impact the running tests in any way.  You can see evidence of this approach in later sessions in the series, read more about NDbUnit at http://ndbunit.googlecode.com ,  and read more about the availability of some of the tooling that makes working with NDbUnit easier in this post: http://unhandled-exceptions.com/blog/index.php/2009/03/16/proteus-unit-test-utility-and-domain-foundation-code-goes-oss/

Hope this helps, and thanks for the comments~!

-Steve B.</description>
		<content:encoded><![CDATA[<p>@Seth:</p>
<p>Great question; those are (obviously) very real concerns.  Later on in subsequent sessions you will begin to see how I leverage a testing support framework called NDbUnit to permit my tests to properly manage state, ensure that expected records are present in the DB before the test, and cleans up after the tests.</p>
<p>I don&#8217;t generally like using DB transaction rollbacks as my method of reverting DB state after tests run b/c there are so many things that can go wrong w that strategy (especially if/when part of the DB methods you might be testing makes use of transactions internally and would need to be aware of outer transaction scope, etc. to properly enlist in the right transaction, etc.).</p>
<p>NDbUnit places this responsibility in a tooling framework that doesn&#8217;t impact the running tests in any way.  You can see evidence of this approach in later sessions in the series, read more about NDbUnit at <a href="http://ndbunit.googlecode.com" rel="nofollow">http://ndbunit.googlecode.com</a> ,  and read more about the availability of some of the tooling that makes working with NDbUnit easier in this post: <a href="http://unhandled-exceptions.com/blog/index.php/2009/03/16/proteus-unit-test-utility-and-domain-foundation-code-goes-oss/" rel="nofollow">http://unhandled-exceptions.com/blog/index.php/2009/03/16/proteus-unit-test-utility-and-domain-foundation-code-goes-oss/</a></p>
<p>Hope this helps, and thanks for the comments~!</p>
<p>-Steve B.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth Petry-Johnson</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-25347</link>
		<dc:creator>Seth Petry-Johnson</dc:creator>
		<pubDate>Wed, 16 Dec 2009 17:15:47 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-25347</guid>
		<description>Steve,

I've watched sessions 1 and 2 and I have a question/comment regarding your test strategy. In multiple places you run some query, such as getting all customers by the first name of "steve", and then you assert that the number of records matches some known constant. For instance, you inspect the DB, see that there are 3 Steves, and you assert that your DAL call yields 3 results.

Obviously, this is extremely brittle. What happens if you eventually test a Create method that creates a new "steve"? Or if you delete a Steve during a delete test? Are you ignoring those cases for the sake of simplicity?

The pattern I normally use is this:

1) In my setup/teardown, I start and rollback a DB transaction;

2) My tests always create the data they expect, usually via [Setup], unless my fixture setup restores the DB to a known and stable state;

3) To test something like GetByFirstName("steve"), I would create TWO customers, Steve and Fred. I can then be confident that my DAL is including only what it should, nothing more and nothing less.

Is this what you would do in production, or do you think this overly complicates the tests?</description>
		<content:encoded><![CDATA[<p>Steve,</p>
<p>I&#8217;ve watched sessions 1 and 2 and I have a question/comment regarding your test strategy. In multiple places you run some query, such as getting all customers by the first name of &#8220;steve&#8221;, and then you assert that the number of records matches some known constant. For instance, you inspect the DB, see that there are 3 Steves, and you assert that your DAL call yields 3 results.</p>
<p>Obviously, this is extremely brittle. What happens if you eventually test a Create method that creates a new &#8220;steve&#8221;? Or if you delete a Steve during a delete test? Are you ignoring those cases for the sake of simplicity?</p>
<p>The pattern I normally use is this:</p>
<p>1) In my setup/teardown, I start and rollback a DB transaction;</p>
<p>2) My tests always create the data they expect, usually via [Setup], unless my fixture setup restores the DB to a known and stable state;</p>
<p>3) To test something like GetByFirstName(&#8221;steve&#8221;), I would create TWO customers, Steve and Fred. I can then be confident that my DAL is including only what it should, nothing more and nothing less.</p>
<p>Is this what you would do in production, or do you think this overly complicates the tests?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob B</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-24554</link>
		<dc:creator>Rob B</dc:creator>
		<pubDate>Fri, 27 Nov 2009 17:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-24554</guid>
		<description>Brilliant job with these screen casts Steve, they're superb!

The code below shows how to use the Criteria Api to get the non-persisted strongly typed collection using group by.  My naming conventions are slightly different to Steve's.

return session.CreateCriteria(typeof (Customer))  
  .SetProjection(Projections.ProjectionList()
    .Add(Projections.Property("FirstName"), "FirstName")
    .Add(Projections.Count("FirstName"), "Count")
    .Add(Projections.GroupProperty("FirstName")))
    .SetResultTransformer(Transformers.AliasToBean(typeof(CustomerFirstNameCounter)))
  .List&lt; CustomerFirstNameCounter &gt;();


Posted some additional info here. 
http://thelongwayback.wordpress.com/2009/11/27/nhibernate-criteria-api-group-by-example-non-persisted-class/</description>
		<content:encoded><![CDATA[<p>Brilliant job with these screen casts Steve, they&#8217;re superb!</p>
<p>The code below shows how to use the Criteria Api to get the non-persisted strongly typed collection using group by.  My naming conventions are slightly different to Steve&#8217;s.</p>
<p>return session.CreateCriteria(typeof (Customer))<br />
  .SetProjection(Projections.ProjectionList()<br />
    .Add(Projections.Property(&#8221;FirstName&#8221;), &#8220;FirstName&#8221;)<br />
    .Add(Projections.Count(&#8221;FirstName&#8221;), &#8220;Count&#8221;)<br />
    .Add(Projections.GroupProperty(&#8221;FirstName&#8221;)))<br />
    .SetResultTransformer(Transformers.AliasToBean(typeof(CustomerFirstNameCounter)))<br />
  .List< CustomerFirstNameCounter >();</p>
<p>Posted some additional info here.<br />
<a href="http://thelongwayback.wordpress.com/2009/11/27/nhibernate-criteria-api-group-by-example-non-persisted-class/" rel="nofollow">http://thelongwayback.wordpress.com/2009/11/27/nhibernate-criteria-api-group-by-example-non-persisted-class/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sbohlen</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-24102</link>
		<dc:creator>sbohlen</dc:creator>
		<pubDate>Tue, 17 Nov 2009 22:01:52 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-24102</guid>
		<description>@Leyu Sisay:

Thanks for the updates -- that's sure to be one of the 'gotchas' from using a freeform query language (HQL, SQL, or whatever): the syntax can change right out from under you on a whim :)

The 'shorthand' HQL form that I was using in the screencasts under 1.2 was deprecated in 2.0 and eliminated in 2.1.x as the default query parser was switched out to be the more strict option.

Thanks again for offering the update!

-Steve B.</description>
		<content:encoded><![CDATA[<p>@Leyu Sisay:</p>
<p>Thanks for the updates &#8212; that&#8217;s sure to be one of the &#8216;gotchas&#8217; from using a freeform query language (HQL, SQL, or whatever): the syntax can change right out from under you on a whim <img src='http://unhandled-exceptions.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The &#8217;shorthand&#8217; HQL form that I was using in the screencasts under 1.2 was deprecated in 2.0 and eliminated in 2.1.x as the default query parser was switched out to be the more strict option.</p>
<p>Thanks again for offering the update!</p>
<p>-Steve B.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leyu Sisay</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-24091</link>
		<dc:creator>Leyu Sisay</dc:creator>
		<pubDate>Tue, 17 Nov 2009 14:35:03 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-24091</guid>
		<description>When using the sample code using NHibernate 2.1.0 or  2.1.1, HQL's with the "select from Customer c" formats fail throwing the following exception.

"NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown"

The HQL's should be changed to "from Customer c" or "select c from Customer c" formats

See the related SO question 
http://stackoverflow.com/questions/1228146/nhibernate-querysyntaxexception</description>
		<content:encoded><![CDATA[<p>When using the sample code using NHibernate 2.1.0 or  2.1.1, HQL&#8217;s with the &#8220;select from Customer c&#8221; formats fail throwing the following exception.</p>
<p>&#8220;NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type &#8216;Antlr.Runtime.NoViableAltException&#8217; was thrown&#8221;</p>
<p>The HQL&#8217;s should be changed to &#8220;from Customer c&#8221; or &#8220;select c from Customer c&#8221; formats</p>
<p>See the related SO question<br />
<a href="http://stackoverflow.com/questions/1228146/nhibernate-querysyntaxexception" rel="nofollow">http://stackoverflow.com/questions/1228146/nhibernate-querysyntaxexception</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://unhandled-exceptions.com/blog/index.php/2008/06/26/summer-of-nhibernate-session-02a-exploring-query-methods-and-syntaxes-cont-screencast-is-available/comment-page-1/#comment-14237</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 29 Apr 2009 22:04:15 +0000</pubDate>
		<guid isPermaLink="false">http://UnhandledExceptions.spaces.live.com/Blog/cns!FC56A7CB585DF52F!371.entry#comment-14237</guid>
		<description>@Ted

I don't know how to respond directly to you, or if this is even relevant for you anymore, but just in case you or anyone else comes through here looking for this answer, I was able to track it down.

http://stackoverflow.com/questions/718887/how-do-i-do-a-custom-projection-with-the-criteria-api-in-nhibernate/751657#751657

That link shows you how to AliasToBean transformer to put your results into a new object.  In Steve's example, it would look something like this:

(Criteria setup...)
.Add(Projections.Property(c.Firstname), "firstname")
.Add(Projections.Property(count(C.Firstname)), "count")
.SetResultTransformer(Transformers.AliasToBean(typeof(CustomerFirstnameCounter)));

The other catch here is that the CustomerFirstnameCounter object needs an empty parameter constructor, rather the parmaterized one the HQL example uses.</description>
		<content:encoded><![CDATA[<p>@Ted</p>
<p>I don&#8217;t know how to respond directly to you, or if this is even relevant for you anymore, but just in case you or anyone else comes through here looking for this answer, I was able to track it down.</p>
<p><a href="http://stackoverflow.com/questions/718887/how-do-i-do-a-custom-projection-with-the-criteria-api-in-nhibernate/751657#751657" rel="nofollow">http://stackoverflow.com/questions/718887/how-do-i-do-a-custom-projection-with-the-criteria-api-in-nhibernate/751657#751657</a></p>
<p>That link shows you how to AliasToBean transformer to put your results into a new object.  In Steve&#8217;s example, it would look something like this:</p>
<p>(Criteria setup&#8230;)<br />
.Add(Projections.Property(c.Firstname), &#8220;firstname&#8221;)<br />
.Add(Projections.Property(count(C.Firstname)), &#8220;count&#8221;)<br />
.SetResultTransformer(Transformers.AliasToBean(typeof(CustomerFirstnameCounter)));</p>
<p>The other catch here is that the CustomerFirstnameCounter object needs an empty parameter constructor, rather the parmaterized one the HQL example uses.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

