﻿<?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>Colin Jack commented on Unreadable Linq</title><description>Good post.
  
  
My problem with Linq is that although its object-oriented the queries are too low level, they tell you about the "how" but not the "what" (and sometimes they don't even tell you the how clearly). This gets old very quickly especially when the queries move out of the repositories and into other areas of the codebase. 
  
  
Linq based DDD Specifications could be the answer as they raise the level a bit, tried using them with Linq to NHibernate and had issues though (ending up trying to use features that are NYI) but I think thats the best hope:
  
  
http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!451.entry
  
  
You could then also use this approach:
  
  
http://codebetter.com/blogs/david_laribee/archive/2008/06/15/super-models-part-1-sexy-specifications.aspx
</description><link>http://ayende.com/3483/unreadable-linq#comment6</link><guid>http://ayende.com/3483/unreadable-linq#comment6</guid><pubDate>Tue, 05 Aug 2008 10:50:35 GMT</pubDate></item><item><title>Fredrik Kalseth commented on Unreadable Linq</title><description>I've been toying with the specification pattern in relation to linq lately aswell, and have been able to get stuff like this working:
  
  
var otherQuery = from customer in customerRepository 
  
                            where customer.IsDelinquent &amp;&amp; 
  
                            customer.HasPendingLitiagion &amp;&amp; 
  
                            customer.HasDebtOver(999) 
  
                            select customer;
  
  
Where f.ex Customer.HasDebtOver() is implemented like so:
  
  
[Specification(typeof(CustomerInDebtSpecification))]
  
public bool HasDebtOver(decimal threshold)
  
{
  
   return new CustomerInDebtSpecification(threshold).IsSatisfiedBy(this);
  
}
  
  
By manipulating the expression tree before it gets passed onto f.ex Linq 2 Sql, we can then substitute the property/method calls that are decorated with the Specification attribute with the appropriate expression as defined by the specification.
  
  
I'm just writing up a post detailing my finished implementation of this which I'll post on my blog soon (http://iridescence.no) - I'd also recommend checking out Luke Marshalls blog (http://mathgeekcoder.blogspot.com/) - he's done some great work with the same ideas.
</description><link>http://ayende.com/3483/unreadable-linq#comment5</link><guid>http://ayende.com/3483/unreadable-linq#comment5</guid><pubDate>Sun, 03 Aug 2008 15:32:39 GMT</pubDate></item><item><title>ungood commented on Unreadable Linq</title><description>If you don't like the syntax, step up to the plate:
  
  
What would be your suggestion for what these queries should look like?
</description><link>http://ayende.com/3483/unreadable-linq#comment4</link><guid>http://ayende.com/3483/unreadable-linq#comment4</guid><pubDate>Sat, 02 Aug 2008 20:09:13 GMT</pubDate></item><item><title>Ayende Rahien commented on Unreadable Linq</title><description>Overloading would make it easier, yes.
  
I am leery of that because of the experience with NHQG, where the complexity just exploded on us.
</description><link>http://ayende.com/3483/unreadable-linq#comment3</link><guid>http://ayende.com/3483/unreadable-linq#comment3</guid><pubDate>Sat, 02 Aug 2008 19:25:57 GMT</pubDate></item><item><title>Chad Myers commented on Unreadable Linq</title><description>@Ayende
  
  
Thanks for the critique. It was my hope that this would spawn some discussion! 
  
  
The syntax stinks, no doubt. I was trying to make clear examples but it appears I totally failed, lol.
  
  
What if the queries didn't allow any options, or they only took parameters (i.e. thresholds and such)? 
  
  
You could also configure the queries to pull their parameters from somewhere else (a rules engine or something?)
  
  
Also, what if I overloaded the &amp;&amp; and || operators so you could do something like:
  
  
var customers = 
  
  repo.Query(
  
      (TopCustomersWithLowDiscounts.Query 
  
           &amp;&amp; DelinquentCustomers.Query) 
  
     || PartnerCustomers.Query );
  
  
  
-c
  
</description><link>http://ayende.com/3483/unreadable-linq#comment2</link><guid>http://ayende.com/3483/unreadable-linq#comment2</guid><pubDate>Sat, 02 Aug 2008 13:45:29 GMT</pubDate></item><item><title>Thomas Eyde commented on Unreadable Linq</title><description>I think Linq hasn't been around long enough for us to discover the dos and don'ts. My guess is that we will get our share, and then some, of ugly code and things totally unsuited for Linq.
  
  
The community will eventually agree on patterns and anti-patterns, but we aren't there yet.
</description><link>http://ayende.com/3483/unreadable-linq#comment1</link><guid>http://ayende.com/3483/unreadable-linq#comment1</guid><pubDate>Sat, 02 Aug 2008 12:15:51 GMT</pubDate></item></channel></rss>