New ASP. NET Dynamic Data Support

Source: Internet
Author: User
New ASP. NET Dynamic Data Support

[Original address] new ASP. NET Dynamic Data Support
[Original article published on] Friday, December 14,200 7 AM

The ASP. NET 3.5 extensions CTP preview released last weekend includes a bunch of great new features.

One of the new features is what we call "ASP. NET Dynamic Data support (Dynamic Data Support. To put it simply, this feature allows you to quickly build a data-driven website that can use the object model of LINQ to SQL (in the future, LINQ to entities, it also allows you not to build any web pages manually.

The best way to look at it in practice is to watch David ebbo's wonderful 17-minute screen broadcast:

You can also follow these steps to get started with dynamic data support:

Step 1: Create an ASP. NET Dynamic Data Website

Install ASP. net 3.5 extensions CTP preview version, you can use vs 2008 or free Visual Web Developer 2008 Express version to create and enable ASP. NET Dynamic Data supports new website projects or new web application projects:

This will create an available new website, including some default template files and CSS style sheets that you can use to customize the look and feel template file:

Step 2: add the LINQ to SQL data model

LINQ to SQL is the built-in o/RM (Object link CER) in. Net 3.5. It allows you to use the. NET class to model relational databases. Then you can use LINQ to query the database and update, insert, and delete data in it. LINQ to SQL fully supports transactions, views, and stored procedures. It also provides a simple way to integrate data verification and business logic rules into your data model.

Start to use ASP. NET Dynamic Data website is the easiest way to add a new LINQ to SQL data model to your project (right-click and choose add new item> LINQ to SQL class ). This calls out the LINQ to SQL class designer. Drag the database data table from your Server Manager to the Designer surface, and define a schema for your database to create some classes (including relationships ):

Step 3: Enable dynamic templates in the project

By default, the ASP. NET Dynamic Data project provides built-in support to create an automatic "scaffolding" view for your LINQ to SQL and LINQ to entities data models. The Dynamic Data Project includes some template pages and user controls, which can automatically create a built-in user interface for browsing, editing, selecting, and deleting data, these interfaces are dynamically built at runtime based on the data models you add to the project's LINQ to SQL or LINQ to entities.

To enable the automatic Scaffolding Support, open the Web. config file of your project, find the dynamicdata section, and set its enabletemplates attribute to true:

Note: This automatic scaffolding feature is disabled by default because it is secure (we need to explicitly set it to enable this feature ).

Note: As you can see above, Asp. the net Dynamic Data configuration section also provides optional URL ing support, which allows you to customize your dynamic scaffold web page to any URL format you want.

Step 4: Run your website

Press F5 to run your project. By default, you will be directed to the default. aspx webpage, which lists all data table objects in your data model:

Note: The default. aspx homepage is a file in the project. If you do not like the webpage, open it and edit it as you want.

Click the name of any data table in the list above, and you will be directed to a dynamic data page, which lists the data in the corresponding data table:

The default data view page automatically creates valid data navigation interfaces, including built-in data paging and editing support (ASP. NET Ajax is enabled ):

Data view web pages automatically infer the relationship between associated objects and provide automatic filtering support:

The data view page automatically displays the relationships between your objects, allowing you to easily navigate between them. For example, note that the category field of a product allows me to go to the category details page of a specific product:

The data view page also supports automatic selection, editing, and deletion. Note: In the in-row editing mode, they will automatically infer a friendly foreign key name (allow you to edit "category" and select a name from the drop-down box, instead of specifying an integer "categoryid ):

All of these work automatically without creating any custom. aspx webpage or writing any custom code. All Web user interfaces are dynamically generated based on your LINQ to SQL or LINQ to entities data model.

Step 5: Further customize the website

All of the above functions are provided for your ORM Data Model, which is of great benefit for your website to start operating quickly. After achieving the basic website experience, you can complete customization, whether it is data verification, business logic level, or user interface level.

You can add standard LINQ to SQL data models and business validation rules to your data models to execute constraints. Dynamic Data web pages automatically execute this logic and provide appropriate error information and verification user interfaces based on this logic.

You can also customize the user interface in any data webpage. Dynamic Data projects allow you to customize the default view of all data webpages on the website, and customize the default view of all field types on the website. You can edit the default template file added to the "/app_shared" folder when creating a dynamic data project:

You only need to edit any file above to customize the appearance of the default data webpage view or default data field.

Then, you can add a. aspx webpage mapped to a specific data view page in the project to overwrite the corresponding user interface. For example, I can add \ products \ listdetails. aspx to the project to overwrite the listdetails behavior of the default product:

Then, you can add any standard ASP. NET data control to the webpage. You can also use the dynamic data-aware ASP. NET data control released in the ASP. NET 3.5 extensions CTP preview. These controls allow you to completely customize the perception of the user interface, while also using the new dynamic metadata provider (Dynamic meta-data provider) to infer the relationship and metadata between your data model classes to provide default behavior.

For details

The above demonstration only involves several scenarios and functions that you can achieve through ASP. NET Dynamic Data projects. For details:

  1. Watch David's webcast
  2. Take a look at the Quick Start document of ASP. NET Dynamic Data
  3. Subscribe to the blogs David ebbo, Scott Hunter, and Marcin dobosz.
  4. Access ASP. NET Dynamic Data forum to ask questions

Want to learn more about LINQ to SQL and how to create a data model class, refer to the following blog posts I wrote earlier (Han xilong of the blog Park has completed 8 of them and will soon post them here ):

  • Part 1: Introduction to LINQ to SQL)
  • Part 2: defining our data model classes
  • Part 3: querying our database
  • Part 4: updating our database
  • Part 5: Binding UI using the ASP: linqdatasource Control
  • Part 6: retrieving data using Stored Procedures
  • Part 7: updating our database using Stored Procedures
  • Part 8: executing custom SQL expressions
  • Part 9: using a custom LINQ expression with the <asp: linqdatasource> Control

You can also watch the wonderful linqand LINQ to SQL "How do I? "Video.

I hope this article will help you,

Scott

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.