Using LINQ with ASP.NET (Part 1)
page 10 of 12
by Scott Guthrie
Feedback
Average Rating: 
Views (Total / Last 10 Days): 23246/ 429

Next Steps

All of my samples above were against in-memory collections.  They show you how you will be able to use LINQ against any .NET object model (includes all the ones you have already).

In my next few LINQ-related blog postings I’ll show how you can go even further, and take advantage of the new DLINQ support to use the above techniques against relational databases as well as the new XLINQ support to work against XML files and structures.  What is great about the LINQ project is that the syntax and concepts are the same across all of its uses – so once you learn how to use LINQ against an array or collection, you also know all the concepts needed to work against a database or even XML file.

For example, if you use DLINQ to generate a Northwinds database mapping of Suppliers and their Products (no code is required to set this up), the below code is all you need to write to obtain and databind a hierarchical database result against a GridView like we did above (note: we are using the same data-shaping technique as our previous sample to only require fetching two columns from the database, and automatically join the products of each supplier as a hierarchical group result):

Listing 19

using System;
using System.Query;
 
public partial class Data_Data2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Northwind db = new Northwind();
 
        GridView1.DataSource = from x in db.Suppliers
                               where x.Country == "USA"
                               orderby x.Country
                               select new { 
                                   x.CompanyName, 
                                    x.Country,
                                    x.Products 
                               };
 
        GridView1.DataBind();
    }
}

No custom SQL syntax or code is required – this is all that needs to be written to efficiently fetch and populate hierarchical data now (note: only the rows and columns needed will be fetched -- DLINQ can use the remote function support within LINQ so that it does not need to materialize or fetch the full database table or all columns from a row).  And it is all type-safe, with full compiler checking, intellisense, and debugging supported.

Even better, the ability to plug-in new LINQ providers (of which DLINQ and XLINQ are just two examples) is completely open – so developers who either build or use existing data providers today (for example: O/R database mappers) can easily integrate their implementations with LINQ to have a seamless developer experience.  Once you know LINQ you will know all the basics needed to program against any of them.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 8 and 3 and type the answer here:

User Comments

Title: LINQ in 2005 and 2008   
Name: Manigandan
Date: 12/16/2008 6:38:07 AM
Comment:
1.We are having this LINQ concept in VS2005 itself...
What is extra facility added in VS2008.

2.If i want to install LINQ separately in VS2005, What is the software that i have to install?
Title: Good one   
Name: Shailendra
Date: 12/9/2008 2:24:22 AM
Comment:
Thanks for all, its very easy to know about linq from these articles.

thanks once again
Title: Trying To Get a Handle On This LINQ Stuff   
Name: D Wiley
Date: 11/21/2008 9:21:36 AM
Comment:
This is on of the best walkthroughs I have seen on the subject.
Title: Leraning LINQ   
Name: Manjeev kumar singh
Date: 10/3/2008 4:00:41 AM
Comment:
This one is most useful article LINQ on web. its really good start for how is beginner in LINQ....
Really thanks
Title: Using Richer Collections   
Name: Nithya K
Date: 9/18/2008 6:58:04 AM
Comment:
Now i got .Its my mistake.
It is very useful
Title: Using Richer Collections   
Name: Nithya K
Date: 9/18/2008 6:00:18 AM
Comment:
i got an error while executing
Title: Using Richer Collections   
Name: Nithya K
Date: 9/18/2008 5:53:19 AM
Comment:
\
\S
\
\
Title: Leraning LINQ   
Name: vanitha
Date: 9/16/2008 1:31:46 AM
Comment:
Very useful in learning the basic concepts of LINQ.
Title: Using LINQ with ASP.NET   
Name: Durai karthik M
Date: 3/15/2008 7:20:50 AM
Comment:
Very clear to understand the LINQ concept . Keep up the good work
Title: -   
Name: martin
Date: 1/21/2008 4:41:46 AM
Comment:
The images aren't shown... you need to remake the picture HTML

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 1/7/2009 7:38:17 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search