LinqDataSource - LINQ to SQL ASP.NET Website Rapid Application Development

LinqDataSource - LINQ to SQL ASP.NET Website Rapid Application Development

by David Hayden ( Florida Web Developer ), Filed: LINQ to SQL

 

In Orcas Beta 2 is the new LinqDataSource Control that allows you to to easily bind a GridView to a LINQ to SQL DataContext Class for simple insert, update, and delete functionality to your SQL Server Database. And by easy, I mean you do not even need to define your insert, update, and delete queries like you need to with the SqlDataSource Control ( note: you could of course specify them )! With the LinqDataSource, you just need to point it to the DataContext Class and give it the name of the table that you want it to query against:

 

<asp:LinqDataSource
    ID="ProductsDataSource"
    ContextTypeName="MyApp.StoreDataContext"
    TableName="Products"
    EnableUpdate="true"
    EnableDelete="true"
    runat="server"
/>

 

Notice we don't need to define any queries above. The LinqDataSource does all that plumbing as well as record paging, too.

Then we just hook it up to a GridView and we have insert, update, and delete of products as well as proper paging of the products in the Products Table:

 

<asp:GridView
    ID="ProductsGridView"
    DataSourceID="ProductsDataSource"
    AllowPaging="true"
    AllowSorting="true"
    DataKeyNames="ProductId"
    runat="server"
/>

 

For smaller web applications where you don't feel you need to use an ObjectDataSource Control, the LinqDataSource Control provides some wonderful rapid application development goodness in you ASP.NET Web Applications when using LINQ to SQL.

 

News Feed: David Hayden ( Florida Web Developer )

Filed: LINQ to SQL

posted on Tuesday, July 24, 2007 10:32 AM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices