﻿<?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>John Farrell commented on Challenge: Efficient querying</title><description>Doesn't being concerned about this go against the stance you posted on performance and ROI a couple of weeks ago?
  
  
I'd wait and see if it matters before tweaking my models or hand writing sql
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment8</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment8</guid><pubDate>Fri, 12 Feb 2010 18:51:18 GMT</pubDate></item><item><title>ivos commented on Challenge: Efficient querying</title><description>What about adding a UserWaitingBook class instead of a many-to-many mapping? Also, there're more data that could be there (ok, it's not the requirement, but it could be), for example the date of the book request, the days the user wants to wait for the book, I don't know... but it could have more information, right?
  
so, with that model, you could do:
  
  
var books = session.CreateQuery("select b from WaitingUser u join fetch Book as b join fetch b.Authors where u.Id = :userId")
  
.SetParameter("userId", 1)
  
.List();
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment7</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment7</guid><pubDate>Fri, 12 Feb 2010 16:38:40 GMT</pubDate></item><item><title>Paul Batum commented on Challenge: Efficient querying</title><description>Sigh, I always forget this blog eats angle brackets.
  
  
By new feature above, I meant lazy properties.
  
(property  name="Image" lazy="true")
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment6</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment6</guid><pubDate>Fri, 12 Feb 2010 15:43:17 GMT</pubDate></item><item><title>Paul Batum commented on Challenge: Efficient querying</title><description>If we use something such as:
  
  
var books = session.CreateQuery("select b from Book as b join fetch b.Authors join b.WaitingUsers as u where u.Id = :userId")                    
  
                    .SetParameter("userId", 1)                    
  
                    .List
&lt;book();
  
  
Where b.WaitingUsers is a the reverse side of the Queue relationship, but mapped as a Noop, then the downsides seems to be:
  
  
a) Unnecessary join to the User table - I can't see a way to tell NH it only has to go as far as the UsersWaitingBooks table to get the userId.
  
  
b) Book image repeated in results. I am thinking that this could be resolved using the new 
&lt;property feature, and then use a multiquery with a seperate query for the image?
  
  
My SQL optimisation skills are pretty weak, I expect there is a much more elegant solution that doesn't rely on fancy mapping features...
&gt;</description><link>http://ayende.com/4397/challenge-efficient-querying#comment5</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment5</guid><pubDate>Fri, 12 Feb 2010 15:40:47 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Efficient querying</title><description>OmariO,
  
Think about the SQL that this will generate
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment4</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment4</guid><pubDate>Fri, 12 Feb 2010 13:35:57 GMT</pubDate></item><item><title>OmariO commented on Challenge: Efficient querying</title><description>If it were LINQ to SQL I would try the following:
  
  
var books = from uq in dc.UserWatingBooks
  
                   where uq.UserId == 
&lt;userid  
                   let b = uq.Book
  
                   select new BookDTO
  
                   { 
  
                     Id          = b.Id, 
  
                     Name    = b.Name, 
  
                     Image    = b.Image, 
  
                     Authors = (from ba in b.BookAuthors
  
                                      select ba.Author.Name).ToArray()
  
                    };
  
  
  
bus.Reply(new MyQueueResponse
  
{
  
    UserId = message.UserId,
  
    Timestamp = DateTime.Now,
  
    Queue = books.ToArray()
  
});
&gt;</description><link>http://ayende.com/4397/challenge-efficient-querying#comment3</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment3</guid><pubDate>Fri, 12 Feb 2010 12:32:28 GMT</pubDate></item><item><title>Richard Dingwall commented on Challenge: Efficient querying</title><description>These days my brain is defaulting to "CQRS" for questions like this...
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment2</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment2</guid><pubDate>Fri, 12 Feb 2010 12:02:57 GMT</pubDate></item><item><title>NC commented on Challenge: Efficient querying</title><description>Plural names?
  
  
You know if you applied Plural to your Prof licensing model you could have a Personal License! :o
</description><link>http://ayende.com/4397/challenge-efficient-querying#comment1</link><guid>http://ayende.com/4397/challenge-efficient-querying#comment1</guid><pubDate>Fri, 12 Feb 2010 11:59:40 GMT</pubDate></item></channel></rss>