Today I've played for the first time with a new features that comes with the .NET Framework 3.5 SP1, the new ASP.NET Dynamic Data support. My comments about this now? Marvellous!! :)
The new ASP.NET Dynamics Data is a feature that (in summary) permits you to quickly build data-driven websites (based on LINQ to SQL or LINQ to Entities) without writing any lines of code. In few minutes you can have a complete data-driven site ready to be extended and customized.
How to do this? Here's a quick sample:
If you have installed .NET 3.5 SP1 and with Visual Studio you create a new Web Site project, now you have the ASP.NET Dynamic Data templates available. Choose the Dynamic Data Web Site template:
Visual Studio automatically creates a new Web Site project with a predefined template, with a master page and a CSS. All is customizable:
Now you have to "attach" the data support to your new web site. .NET 3.5 introduces the new LINQ to SQL that allows you to model your relational database using .NET classes and query it using the new LINQ features.
So, you can add a new item to your project and in the item window you have to choose LINQ to SQL Classes:
This will open the LINQ to SQL class designer inside Visual Studio and here you can drag your database tables directly via the Visual Studio server explorer.
For this sample I've opened a Dynamics NAV Database that I have on my local SQL Server and I've choose to drag the Customer table and the Sales Header table. After loading the table, I've defined a relation between Customer (field No.) and Sales Header (field Sell to Customer No.). LINQ to SQL maps all the classes for you:
Linq to SQL uses a DataContext to manage it's access to the database as well as tracking changes made to entities retrieved from the database. For my solution I've renamed the just created DataContext to NAVDataContext:
Now, to associate the newly created LINQ to SQL DataContext to the ASP.NET Dynamic Data, you have to open the Global.asax file of your project and uncomment and modify the following line of code:
As you can see in the picture, you have to associate your newly created DataContext (in my sample is NAVDataContext) and I've choosed to set ScaffoldAllTables to true in order to have an interface for all the tables in the DataContext (this is set as default to false for security reason).
That's all... now you have a "ready to go" ASP.NET 3.5 Data Driven website! If you launch the project from Visual Studio, this is the result: the main page shows you the table you have:
By clicking on a table name, you can see the records and interact with them (Edit, Delete, Details, Insert):
Every column of a table has a native ordering support. Every page has also a built-in paging support (ASP.NET AJAX enabled):
For every record (Customers on my sample) you have a link that permits you to go to the related entity (in my sample it permits you to view the Sales Header for the selected customer):
If you click on the link, this is the result:
As you can see, you're redirected to a detailed page for the related entity. The browser URL receives the parameter of your data relation (in my sample it's the customer code).
Another interesting feature that you can see on the figure (check my red arrow) is that on your related entity page you have an automatic filtering support:
As you can see, this is simple and extremely powerful. Obviously, all the things you've see in this sample are fully customizable to suits your needs. ASP.NET Dynamics Data rocks!! ;)
Technorati Tag:
.NET,
ASP.NET,
LINQ,
Data