Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2008, 09:27 AM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 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
Did someone here help you? Click on their post!
 
Old March 21st, 2008, 10:05 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 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
 
Old March 21st, 2008, 10:11 AM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old March 21st, 2008, 10:23 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 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
 
Old March 21st, 2008, 10:40 AM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old March 21st, 2008, 10:46 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 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
 
Old March 21st, 2008, 10:52 AM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old March 21st, 2008, 11:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 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
 
Old March 21st, 2008, 11:13 AM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old March 21st, 2008, 02:42 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.