p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > C# and C > C# 2008 > BOOK: Professional Refactoring in C# & ASP.NET
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Refactoring in C# & ASP.NET
This is the forum to discuss the Wrox book Professional Refactoring in C# & ASP.NET by Danijel Arsenovski; ISBN: 9780470434529

Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Refactoring in C# & ASP.NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 28th, 2009, 05:55 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,250, Level: 27
Points: 4,250, Level: 27 Points: 4,250, Level: 27 Points: 4,250, Level: 27
Activity: 30%
Activity: 30% Activity: 30% Activity: 30%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
Default Chapter 13 : Querying Objects

In Listing 13-4, the author provides the following logic for obtaining the most prolific author (i.e. the author with the greatest number of books) in the example given:

Code:
var prolificAuthor = (
    from author in authors
    orderby author.Books.Count() descending
    select author
    ).First();
While this works, it is not as efficient as it could be, in that it relies on ordering the query, which is a very expensive operation.

An alternative way of doing this would be as follows:

Code:
var prolificAuthor = 
    (from author in authors
    where author.Books.Count() == authors.Max(auth => auth.Books.Count())
    select author).First();
This code selects the first author from a list of authors in which their book count equals the maximum book count. It accomplishes the same thing, but is much quicker, as it does not involve any ordering.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 12 - Querying XML Views janeming BOOK: Professional SQL Server 2005 XML ISBN: 0-7645-9792-2 0 April 13th, 2009 06:15 PM
Chapter 13 - Forms as objects Zave BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 0 August 22nd, 2007 01:23 AM
Chapter 13 bwoll BOOK: Beginning Access 2003 VBA 1 June 7th, 2007 04:57 PM
Chapter 13 ibjc01 BOOK: Beginning ASP.NET Dynamic Websites w/ Web Matrix 1 November 23rd, 2006 12:10 AM
Chapter 13 ElMorenito BOOK: Beginning ASP 3.0 0 January 14th, 2005 02:56 PM



All times are GMT -4. The time now is 08:12 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc