<?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: Query Objects with Repository Pattern Part 2</title>
	<atom:link href="http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/</link>
	<description>Software development, testing, and techie life</description>
	<lastBuildDate>Thu, 08 Mar 2012 22:19:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Bj&#246;rn Rochel</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-501</link>
		<dc:creator>Bj&#246;rn Rochel</dc:creator>
		<pubDate>Mon, 15 Sep 2008 19:23:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-501</guid>
		<description>Hey Chad,

does this code run with Linq to NHibernate or some other Linq provider? 

I&#039;ve tried to get it work with both NHibernate and EF. Both exited with similar exceptions ala &quot;unknown expression&quot; or &quot;expression type not supported&quot;.

P.S: Don&#039;t get me wrong I&#039;m totally on your side when it comes to testing with in memory repositories (which by the way works exellent with that approach). I just wanted to see it in a action on a db . . . .</description>
		<content:encoded><![CDATA[<p>Hey Chad,</p>
<p>does this code run with Linq to NHibernate or some other Linq provider? </p>
<p>I&#8217;ve tried to get it work with both NHibernate and EF. Both exited with similar exceptions ala &#8220;unknown expression&#8221; or &#8220;expression type not supported&#8221;.</p>
<p>P.S: Don&#8217;t get me wrong I&#8217;m totally on your side when it comes to testing with in memory repositories (which by the way works exellent with that approach). I just wanted to see it in a action on a db . . . .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: flipdoubt</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-500</link>
		<dc:creator>flipdoubt</dc:creator>
		<pubDate>Fri, 29 Aug 2008 11:54:24 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-500</guid>
		<description>Any chance you could make the repository implementation and the tests available in a download so Community Server doesn&#039;t get its mitts all over it?</description>
		<content:encoded><![CDATA[<p>Any chance you could make the repository implementation and the tests available in a download so Community Server doesn&#8217;t get its mitts all over it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lucas Goodwin</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-499</link>
		<dc:creator>Lucas Goodwin</dc:creator>
		<pubDate>Fri, 08 Aug 2008 22:53:39 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-499</guid>
		<description>I like the idea.  On the repository per root versus single repository bit.  We&#039;ve done things both ways and find the repository per model object works best.  More explicit and easier to maintain (less concerns merged together).

However, we don&#039;t use the specification/et al patterns in our repositories.  They&#039;re specific methods for specific requests, which are mapped to data adapters internally.

Our reasoning is thus: If I want all the active users from a user repository, I don&#039;t care how the database is setup, so I don&#039;t care that the underlying query could contain &quot;business&quot; logic in the where clause.  All I care about is that the data adapter is returning to me active user objects.

This allows the DB schema to change dramatically and only affects the SQL queries in the DataAccess layer.  Not the repository in the business layer.

Hopefully that makes sense.

When testing the repositories, we just mock the adapters.  When testing the adapters, we are hitting the DB directly, but that&#039;s ok as they&#039;re integration tests, not regularly run unit tests.</description>
		<content:encoded><![CDATA[<p>I like the idea.  On the repository per root versus single repository bit.  We&#8217;ve done things both ways and find the repository per model object works best.  More explicit and easier to maintain (less concerns merged together).</p>
<p>However, we don&#8217;t use the specification/et al patterns in our repositories.  They&#8217;re specific methods for specific requests, which are mapped to data adapters internally.</p>
<p>Our reasoning is thus: If I want all the active users from a user repository, I don&#8217;t care how the database is setup, so I don&#8217;t care that the underlying query could contain &#8220;business&#8221; logic in the where clause.  All I care about is that the data adapter is returning to me active user objects.</p>
<p>This allows the DB schema to change dramatically and only affects the SQL queries in the DataAccess layer.  Not the repository in the business layer.</p>
<p>Hopefully that makes sense.</p>
<p>When testing the repositories, we just mock the adapters.  When testing the adapters, we are hitting the DB directly, but that&#8217;s ok as they&#8217;re integration tests, not regularly run unit tests.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Myers</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-498</link>
		<dc:creator>Chad Myers</dc:creator>
		<pubDate>Mon, 04 Aug 2008 16:13:22 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-498</guid>
		<description>@Chris Ortman

Absolutely right about the naming. I should&#039;ve used Specification instead. 

@Akash

I&#039;ve seen that before. That article helped me finally break through my first barrier of groking Linq.  I had forgotten about it until just now. Thanks for reminding me and for dropping a good link for the viewers here.

@Chris Martin

Yes, I&#039;m betting that pretty much all providers will be Linq2X based from now on (Linq2Sql, Linq2NHibernate, Linq2LLBLGen, Linq2EntityFramework, etc).

As far as converting an expression tree to SQL, that&#039;s what Linq2SQL is all about.

But, back to your point, you&#039;re correct: this would not be an appropriate solution for old-fashioned unadulterated ADO.NET usage.</description>
		<content:encoded><![CDATA[<p>@Chris Ortman</p>
<p>Absolutely right about the naming. I should&#8217;ve used Specification instead. </p>
<p>@Akash</p>
<p>I&#8217;ve seen that before. That article helped me finally break through my first barrier of groking Linq.  I had forgotten about it until just now. Thanks for reminding me and for dropping a good link for the viewers here.</p>
<p>@Chris Martin</p>
<p>Yes, I&#8217;m betting that pretty much all providers will be Linq2X based from now on (Linq2Sql, Linq2NHibernate, Linq2LLBLGen, Linq2EntityFramework, etc).</p>
<p>As far as converting an expression tree to SQL, that&#8217;s what Linq2SQL is all about.</p>
<p>But, back to your point, you&#8217;re correct: this would not be an appropriate solution for old-fashioned unadulterated ADO.NET usage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Martin</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-497</link>
		<dc:creator>Chris Martin</dc:creator>
		<pubDate>Mon, 04 Aug 2008 15:15:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-497</guid>
		<description>By using LINQ constructs in your Repository, are you not tying your application to LinqTo*? What if I have a client that requires plain old ADO.NET? (current situation.; ) )

I&#039;m not sure how I could convert an ExpressionTree to SQL.</description>
		<content:encoded><![CDATA[<p>By using LINQ constructs in your Repository, are you not tying your application to LinqTo*? What if I have a client that requires plain old ADO.NET? (current situation.; ) )</p>
<p>I&#8217;m not sure how I could convert an ExpressionTree to SQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Akash Chopra</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-496</link>
		<dc:creator>Akash Chopra</dc:creator>
		<pubDate>Mon, 04 Aug 2008 10:17:29 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-496</guid>
		<description>Something similar: http://www.albahari.com/nutshell/predicatebuilder.html</description>
		<content:encoded><![CDATA[<p>Something similar: <a href="http://www.albahari.com/nutshell/predicatebuilder.html" rel="nofollow">http://www.albahari.com/nutshell/predicatebuilder.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Ortman</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-495</link>
		<dc:creator>Chris Ortman</dc:creator>
		<pubDate>Sun, 03 Aug 2008 02:13:09 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-495</guid>
		<description>You don&#039;t _need_ a DB, but I prefer it probably because I am not 100% comfortable with the NHibernate criteria API and I want to make sure I am using it correctly.

ISpecification&lt;T&gt; is perfectly testable without a DB though, and usiing an ISpecification&lt;T&gt; doesn&#039;t require a repository. That&#039;s why on my interface I have just IsSatisfiedBy(T object).

I think our two approaches are very similar just different naming between specification and query. 
In terms of just naming, I think query is more suggestive that there is a database than specification. Dunno if that is good or bad though</description>
		<content:encoded><![CDATA[<p>You don&#8217;t _need_ a DB, but I prefer it probably because I am not 100% comfortable with the NHibernate criteria API and I want to make sure I am using it correctly.</p>
<p>ISpecification<t> is perfectly testable without a DB though, and usiing an ISpecification</t><t> doesn&#8217;t require a repository. That&#8217;s why on my interface I have just IsSatisfiedBy(T object).</p>
<p>I think our two approaches are very similar just different naming between specification and query.<br />
In terms of just naming, I think query is more suggestive that there is a database than specification. Dunno if that is good or bad though</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Myers</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-494</link>
		<dc:creator>Chad Myers</dc:creator>
		<pubDate>Sun, 03 Aug 2008 01:19:21 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-494</guid>
		<description>@Colin:

Dang, that Ian Cooper!  I knew I had seen something like this before but my googling game up empty. Spot on. 

I know my FI sucks, I was trying to make a simple point and everyone is beating me up over it, lol.   Ian&#039;s approach is very similar, but more modular.  

One point about all this is that the specification is not inherently dependent upon the repository and can be tested in isolation.  There&#039;s also a distinct possibiliy of externalizing the specifications as a DSL that might be easier to tweek outside of the main application code. This is potentially a slippery slope, though, and subject to abuse. But if you keep a tight ship and require that all changes to the spec DSL have corresponding tests and don&#039;t get rolled out to production without having been tested, it&#039;s just as good as having it internal to the app quality-wise, but much easier for the stakeholders to see and visualize when reading the requirements-represented-as-code.

@Chris

Because the queries are inherently business logic. The statement that a &quot;Top Customer&quot; is one that has sales over a certain amount and is &#039;preferred&#039; is business logic.  I turn the question back around on you: Why do I need a DB to test my business logic?  Or better yet,  Why does my business logic require a repository?
</description>
		<content:encoded><![CDATA[<p>@Colin:</p>
<p>Dang, that Ian Cooper!  I knew I had seen something like this before but my googling game up empty. Spot on. </p>
<p>I know my FI sucks, I was trying to make a simple point and everyone is beating me up over it, lol.   Ian&#8217;s approach is very similar, but more modular.  </p>
<p>One point about all this is that the specification is not inherently dependent upon the repository and can be tested in isolation.  There&#8217;s also a distinct possibiliy of externalizing the specifications as a DSL that might be easier to tweek outside of the main application code. This is potentially a slippery slope, though, and subject to abuse. But if you keep a tight ship and require that all changes to the spec DSL have corresponding tests and don&#8217;t get rolled out to production without having been tested, it&#8217;s just as good as having it internal to the app quality-wise, but much easier for the stakeholders to see and visualize when reading the requirements-represented-as-code.</p>
<p>@Chris</p>
<p>Because the queries are inherently business logic. The statement that a &#8220;Top Customer&#8221; is one that has sales over a certain amount and is &#8216;preferred&#8217; is business logic.  I turn the question back around on you: Why do I need a DB to test my business logic?  Or better yet,  Why does my business logic require a repository?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Ortman</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-493</link>
		<dc:creator>Chris Ortman</dc:creator>
		<pubDate>Sat, 02 Aug 2008 23:30:52 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-493</guid>
		<description>I don&#039;t see much point in testing queries without hitting the db though.

If the object is more akin to a finder and has some sophisticated query generation logic then I would do something like this:

var userRepository = new UserRespository(new InMemoryRepository&lt;User&gt;())

or

var expectedCriteria = DetachedCriteria.For&lt;User&gt; 
//... build the criteria I expect

Assert.Equal(expectedCriteria.ToString(), new ComplexSpecification().CreateCriteria().ToString());</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see much point in testing queries without hitting the db though.</p>
<p>If the object is more akin to a finder and has some sophisticated query generation logic then I would do something like this:</p>
<p>var userRepository = new UserRespository(new InMemoryRepository<user>())</p>
<p>or</p>
<p>var expectedCriteria = DetachedCriteria.For</user><user><br />
//&#8230; build the criteria I expect</p>
<p>Assert.Equal(expectedCriteria.ToString(), new ComplexSpecification().CreateCriteria().ToString());</user></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://lostechies.com/chadmyers/2008/08/02/query-objects-with-repository-pattern-part-2/#comment-492</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Sat, 02 Aug 2008 20:47:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chad_myers/archive/2008/08/02/query-objects-with-repository-pattern-part-2.aspx#comment-492</guid>
		<description>On the repository approach, in my view it should definitely be one per aggregate root if you&#039;re doing standard DDD (I don&#039;t think Fowler is so specific though).

Anyway in my view the Specification pattern is the best solution so I&#039;ve been trying to use the Linq Specification approach that Ian Cooper blogged about:

http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!451.entry

Not that different than your approach but although the idea is sound it doesn&#039;t currently work that well with Linq To NHibernate. 

Also I&#039;m not sure the fluent interface here is working for me, perhaps more specifications that you combine? Dunno.

@Chad
On testing, there was some discussion on the DDD newsgroup about this ages ago. 

I&#039;ve tended to run the tests against the database but ultimately you could have specific repositories with methods that have a nice interface that just wrap the creation and execution of the specifications (Evans/Fowler both talk about this).</description>
		<content:encoded><![CDATA[<p>On the repository approach, in my view it should definitely be one per aggregate root if you&#8217;re doing standard DDD (I don&#8217;t think Fowler is so specific though).</p>
<p>Anyway in my view the Specification pattern is the best solution so I&#8217;ve been trying to use the Linq Specification approach that Ian Cooper blogged about:</p>
<p><a href="http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!451.entry" rel="nofollow">http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!451.entry</a></p>
<p>Not that different than your approach but although the idea is sound it doesn&#8217;t currently work that well with Linq To NHibernate. </p>
<p>Also I&#8217;m not sure the fluent interface here is working for me, perhaps more specifications that you combine? Dunno.</p>
<p>@Chad<br />
On testing, there was some discussion on the DDD newsgroup about this ages ago. </p>
<p>I&#8217;ve tended to run the tests against the database but ultimately you could have specific repositories with methods that have a nice interface that just wrap the creation and execution of the specifications (Evans/Fowler both talk about this).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
