Upload
kunal-uppal
View
227
Download
0
Embed Size (px)
Citation preview
8/3/2019 Dynamic Data in Asp.net
1/13
Dynamic Data
in .NET 4.0
I n f i n i t e C o m p u t i n g S y s t e m s
C e d a r R a p i d s , M u m b a i , B a n g k o k
1 1 / 9 / 2 0 1 1
Kunal Uppal
Document explains the features of Dynamic Data and their
use in a web application. This includes the scenarios in
which an architect or an application designer should choose
to use Dynamic Data features.
8/3/2019 Dynamic Data in Asp.net
2/13
INTRODUCTION
Almost all web application that we create has always needed some kind of an interface to
manage the data in the underlying table. Even to manage the basic CRUD (Create, Read ,
Update and Delete) operations on a table, it still takes some amount of doing for developers
to create data access classes, validations, data bound controls such as Gridview with sorting
and paging, form or list views. Entire development of a single screen for a table takes hours
of development causing estimates to bloat up which in turns gets passed to your clients,
who is already reeling under the high cost of maintenance.
In our recent project, we had some 7 screens to create for the application administrators to
perform add/edit/delete operation on the master data. Something which looked very obvious
was actually not less than 120 hour of development and testing.
Now with Dynamic Data in .NET 4.0, managing this is very easy. Precisely, ASP.NET
dynamic data provides a framework which enables quick building of functional data driven
application that are based on Microsoft ORM i.e. LINQ TOSQL or Entity framework data
model. It has added smart validation and ability to change the display with templates to
DetailsView, FormView, GridView, and ListView controls. As per Microsoft, the dynamic
data framework enables major usability and RAD development changes to work with data
model. The LINQTOSQL or EF can be registered with dynamic data to result into a fully
functional web site. Even though the entire code is generated for you but its purely
customizable and even third party controls like Telerik and Devexpress are giving support
to dynamic data in their data bound controls.
It supports all CRUD operations. We will explore dynamic data website with .NET
framework 4.0.
8/3/2019 Dynamic Data in Asp.net
3/13
Scenarios
Use of Dynamic Data in web application is specific and is not meant for all the scenarios of
application design. In cases, when you dont have direct access to the database or dontwant yourself to open your database directly to have unrestricted access of your schema,
you would find Dynamic data of less use.
Dynamic data has lot of use in a small scale application or a part in big application where
you need to build admin specific functionality to add, edit or delete records from a table.
This is still some saving in a small to medium size application where the entire admin
section can easily take 10-15% of your overall development cost.
Below are the scenarios in which you can leverage the power of Dynamic Data.
Looking for CRUD operations on a table
If you are looking for a standard implementation of providing Create/Update/Delete
operations on your tables, you will find Dynamic data as a great time savior that too with a
very stable implementation. With Standard UI screens, validation messages and consistent
layout of controls, it becomes easy to develop and test the basic scenarios. In our recent
sample version, we were able to create 7-8 screens in less than 5 minutes.
Rapid Application Development in a data driven web application
Time is a big factor and cost depends on it. If all you need is to give a feature in your
application that will enable the users to perform CRUD operations and abstracting the
relational constraints on the underlying table
If you need to create something much customized for your clients then you will find lot of
pain in customizing the dynamic data implementation although the entire source code is
generated is open for use. It still involves some amount of learning curve when you need big
changes in the dynamic data source code.
Use Microsoft built in framework to build User Interface and data
validation
Dynamic data works on templates, Microsoft has provided default templates which can be
changed as well. If you want a feature rich UI including form views, grid views or list to
8/3/2019 Dynamic Data in Asp.net
4/13
perform CRUD operations, Dynamic data gives you a ready-made implementation and
makes it very easy for developers to implement them in quicktime. Through Data
Annotations on your entity you can easily build validations over your entities. It will pick
up things like required fields, data types and maximum lengths. You can also manually
assign validation rules to your classes using metadata and validation attributes.
Separation of concerns along with Rapid Development Methodology
Dynamic data provide a separation of concerns between business logic and web forms.
Database-tier objects are used to describe the attributes of a column, such as validation
rules and column name. The web form no longer needs to determine the right data entry
control or validators. Instead, smart web controls gather and format those controls for you.
8/3/2019 Dynamic Data in Asp.net
5/13
Features
Dynamic data Framework inludes the following features.
1. DataModelling2. Scaffolding
3. Templating
4. Customization
Data Modelling:
It is a method used to define and analyze data requirements needed to support the business
porcess of an organization. The data requirements are recorded as a conceptual data model
with associated data definitions.
Dynamic Data supports the LINQ-to-SQL data model and the ADO.NET Entity Framework
data model. You can include multiple instances of data models in a Web application, but the
models that are used in Dynamic Data must be of the same type.
Scaffolding:
Scaffolding is a mechanism that enhances the existing ASP.NET page framework by
dynamically displaying pages based on the data model. Scaffolding provides the following
capabilities:
1.) Minimal or no code to create a data-driven Web application.2.) Quick development time.
3.) Built-in data validation based on the database schema.
4.) Automatic data selection created for each foreign key or Boolean field .
Templating:
Dynamic data uses templates to provide the Default view of the dataContext with the
Scaffolding.
1. Page templates are ASP.NET Web pages that are configured to display data from anytable that is available to Dynamic Data.
2. Dynamic Data uses field templates to render the UI for displaying and editing individual
data fields. It determines the appropriate field template from the data field types.
The DetailsView and GridView controls have been extended to display fields by using
templates instead of by using hard-coded rules that are programmed in the controls.
8/3/2019 Dynamic Data in Asp.net
6/13
Customization:
We can customize the templates to change their appearance or to specify which controls
they use for rendering. This makes it very easy to make a change in one place in your site
that specifies how to present dates for editing, as one example. FormView and ListView
controls can implement similar behavior by using a DynamicControl object in their
templates and by specifying which field in the row to display. Dynamic Data will then
automatically build the UI for these controls based on the templates that you specify.
Validation is significantly improved in the controls as well. For example, if a column in the
database is limited to 50 characters, and if a column is marked as not nullable, a
RequiredFieldValidator control is automatically enabled for the column.
8/3/2019 Dynamic Data in Asp.net
7/13
Sample Application using Dynamic DataEnvironment : .NET 4.0, Visual Studio 2010
Database : Sample Adventure Works DB
Step 1Create a web application using a template ASP.Net Dynamic Data Entities Web Application. You can
also choose LINQToSQL but if you are looking for POCO templating and other specific features of Entity
Framework such as lazy loading then it is always better to consider it over LINQ to SQL.
8/3/2019 Dynamic Data in Asp.net
8/13
Step 2Add an ADO.NET Entity Data Model into the project.
Step 3
If you are taking a top down approach of building entities then choose Empty model but as we are going
to use AdventureWorks database, choose option Generate from Database for generating the data
model from database.
8/3/2019 Dynamic Data in Asp.net
9/13
Step 4:
Choose the database and database connection.
8/3/2019 Dynamic Data in Asp.net
10/13
Step 5
Select the database objects like Tables, views to be included in the model.
Step 6:
Register your model in Global.asax. This is where you set the scaffolding as well. Usually set it to false
and mention it only for the tables you want to make it enabled. To enable scaffolding individually, you
have to mention that at class level.
8/3/2019 Dynamic Data in Asp.net
11/13
Step 7:
Make sure that model namespace is referred in the connection string of web.config file.
Run the application and you will find name of all tables for which scaffolding was set to true.
8/3/2019 Dynamic Data in Asp.net
12/13
Screen 1
This is the default page loaded into the browser when one runs the application. This lists all the tables in
the data model.
Screen 2:
This is the List page loadedinto the browser when one clicks the table in the default page and show
the records in the selected table with options for performing CRUD operations.
8/3/2019 Dynamic Data in Asp.net
13/13
Conclusion
ASP.NET Dynamic Data can be used for lookup and Master table maintenance, but that is not the only
use of it. We can use dynamic data for prototyping the applications, rapid development of web sites.
Although dynamic data is fully customizable but it is to be carefully evaluated during design whether it
will be worth customizing it or not.
The great advantage of this framework is that it makes it super easy for us to build those really simple
UIs that we always need for managing administrative data, etc. Framework has a lot of promise for mid-
level apps too. It provides a really nice layer of abstraction for pushing data in and out of a UI. With a
little work, the templates could be customized as well.