Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 21st, 2008, 09:27 AM
jminatel's Avatar
Wrox Staff
Points: 17,437, Level: 57
Points: 17,437, Level: 57 Points: 17,437, Level: 57 Points: 17,437, Level: 57
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,933
Thanks: 57
Thanked 128 Times in 97 Posts
Default LINQ to SQL example for TheBeerHouse in Wrox Blox

Doug Parsons, who many of you will know from these forums for all of his fantastic answers to many ASP.NET questions has written for Wrox a short example Migrating to LINQ to SQL in TheBeerHouse and ASP.NET 2.0 Website Programming Problem Design Solution to help anyone who wants to get started with a LINQ to SQL upgrade for their TheBeerHouse site get going.

Here's Doug's description of the content, and there's a full table of contents for the 34 pages Wrox Blox on the page for it:
LINQ to SQL has quickly become a hot topic with the release of ASP.NET 3.5, so it makes sense that the TheBeerHouse application gets an upgraded Data Access Layer leveraging this new technology!
This Wrox Blox demonstrates various LINQ to SQL techniques to use in upgrading the “Articles” portion of TheBeerHouse application. The first step is migrating TheBeerHouse project from an ASP.NET 2.0 to an ASP.NET 3.5 application. Next, create a LINQ to SQL class (DBML) mapping file that will encapsulate the entire Data Access Layer for this project. Readers will become comfortable working with Entities (Tables), navigating Associations (Relationships), and working with stored procedures from a LINQ standpoint, throughout the implementation.

While TheBeerHouse has been ported to Visual Basic .NET, the author uses C# throughout this Wrox Blox, so readers should have at least an intermediate level of understanding with C#.

Code: The code is now available at the usual location at:
http://www.wrox.com/WileyCDA/WroxTit...-DOWNLOAD.html

Jim Minatel
Acquisitions Director
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Wrox online library: http://wrox.books24x7.com
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Blog: http://p2p.wrox.com/content/blogs/jminatel
Wrox on Twitter: http://twitter.com/wrox
Did someone here help you? Click on their post!
  #2 (permalink)  
Old March 21st, 2008, 10:05 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

this sounds great. am just going to buy the download and have a look thro' it and will probably look to creating a set of templates for the site generator based on the concepts.

nice to see doug having a 1st crack at this.

[edit] it would be 'nice' to include a download of the code from the same page on the account that the pdf came from just to see it in action. any chance of doing this??
jimi

http://www.originaltalent.com
  #3 (permalink)  
Old March 21st, 2008, 10:11 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hi Jimi,

Enjoy the article! I also would be very interested to know what you (and the rest of the community for that matter) think of it.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #4 (permalink)  
Old March 21st, 2008, 10:23 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

doug - so far so good (tho' haven't opened vs08 yet to try the concepts. as i mentioned above, it would be a great idea to supply the code that you've worked on to get a feel for the layout etc..)

will keep you posted, tho' am off on holiday for 3 weeks (from sunday), so might not be quite as quick to respond to the article as i'd usually be...

[edit] it would be useful also to perhaps see a little bit of linq that demonstrates the use of paged recordsets along the lines of the following (calssic sql):

string sqlQuery = "SELECT * FROM (" + string.Format("SELECT TOP {1} *, ROW_NUMBER() OVER (ORDER BY {0}) AS RowNum
FROM FileUploads", sortExpression != "" ? sortExpression : "AddedBy ASC", upperBound) + ")
AS AllFileUploads WHERE RowNum BETWEEN @Start AND @End ORDER BY RowNum ASC";

just a thought for us lazy types :-)

jimi

http://www.originaltalent.com
  #5 (permalink)  
Old March 21st, 2008, 10:40 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

3 Weeks of vaction, must be nice! Anywho. I shot Jim an email about getting a link to the source code posted so I will let you know when that happens.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #6 (permalink)  
Old March 21st, 2008, 10:46 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

doug - thanks for that, much appreciated. as for the 3 weeks vacation, sounds nice from a distance until you remember that there will be 4 kids in tow!! :)

jimi

http://www.originaltalent.com
  #7 (permalink)  
Old March 21st, 2008, 10:52 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Paging is quite simple using LINQ, a basic method might be something like this:

private void BindDataSource(int rowNumber)
{
   TBHDataContext ctx = new TBHDataContext();
   var articles = from a in ctx.Articles
                  where a.ArticleID >= 1;
   gv.DataSource = articles.Skip(rowNumber).Take(15);
   gv.DataBind();
}

The Skip() and Take() methods is where the magic happens.  Take(15) returns the first 15 records starting from the Row position defined in Skip().  So if rowNumber = 1 then Take(15) would return the first 15 records in your result set.

hth.

[edit]: The obvious question might be: "Thats great but how do I know what to skip by?" In the case of the GridView if you handle the PageIndexChanging event you could do something like this:

protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gv.PageIndex = e.NewPageIndex;
   BindDataSource(GetNextPage(e.NewPageIndex , gv.PageSize));
}

private int GetNextPage(int pageIndex, int pageSize)
{
   if(pageIndex == 1){ return 1; }
   else
   {
     return ((pageIndex * pageSize) - (pageSize - 1));
   }
}

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #8 (permalink)  
Old March 21st, 2008, 11:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

Quote:
quote:Originally posted by dparsons
 Paging is quite simple using LINQ, a basic method might be something like this:

private void BindDataSource(int rowNumber)
{
   TBHDataContext ctx = new TBHDataContext();
   var articles = from a in ctx.Articles
                  where a.ArticleID >= 1;
   gv.DataSource = articles.Skip(rowNumber).Take(15);
   gv.DataBind();
}

The Skip() and Take() methods is where the magic happens.  Take(15) returns the first 15 records starting from the Row position defined in Skip().  So if rowNumber = 1 then Take(15) would return the first 15 records in your result set.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
doug, i presume there's a way to do sorting on the linq object as well?? (i.e. if clicking on column headers etc..)

jimi

http://www.originaltalent.com
  #9 (permalink)  
Old March 21st, 2008, 11:13 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes that is possible though you would probably want to use a LinqDataSource to achieve this (as a bonus you could also set your gridview up to use paging, editing, etc with this control)

http://msdn2.microsoft.com/en-us/lib...atasource.aspx

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #10 (permalink)  
Old March 21st, 2008, 02:42 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 10 Times in 9 Posts
Default

doug - any chance of seeing a version 1.01 of the pdf with this stuff (LinqDataSource, pagin, editting etc) included just to see how all the component pieces fit together (that way all of the beerhouse functionailty using linq would be showcased).

fingers xx'd - :-0

jimi

http://www.originaltalent.com
 


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ to SQL in TheBeerHouse zhoux BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 1st, 2008 07:37 AM
Technical Editor: LINQ and TheBeerHouse Wrox Blox jminatel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 August 30th, 2008 12:11 AM
LINQ to SQL example for TBH - Wrox Blox Errata dparsons BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 26th, 2008 09:25 AM
LINQ in ASP.NET 3.5 Project Wrox Blox available jminatel ASP.NET 2.0 Professional 0 October 8th, 2007 09:29 PM
LINQ in ASP.NET 3.5 Project Wrox Blox available jminatel ASP.NET 3.5 Professionals 0 October 8th, 2007 09:26 PM



All times are GMT -4. The time now is 02:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.