Sunteți pe pagina 1din 15

IT405: E-Portals Development

Building a Web 2.0 Portal with ASP.Net 3.5


Al Zabir, Omar (2008)

Chapter 4: Building the Data and Business Layer


Using .Net 3.5
Objectives
By the end of week 5 you should be able to:

Understand LINq to SQL features.


Recognize data models.
Identify inactive user and related data.
Describe windows workflow foundation.
Implement dashboard faade.
Objectives

The data and business layer uses two features: Windows Workflow Foundation (WF) and LINQ
The types of LINQ:
Introducing LINQ LINQ to Objects
LINQ to XML(XLINQ)
LINQ to DataSet
LINQ to SQL (DLINQ)
Understand LINQ to SQL features: LINQ to Entities
LINQ - Language Integrated Query - is
a set of C# 3.0 language and .NET 3.5
framework features.
LINQ is used to writing structured Managing relational
queries over local object collections and data as objects without
losing the ability to
remote data sources. query
With LINQ, you can query any collection
that implements IEnumerable<>,
including tables in a database.
Introducing LINQ to SQL
LINQ to SQL makes the task of writing a data access layer easier.
Object Relational Mapping Framework
You design the database that the application will use.
Then you use the Visual Studio 2008 Object/Relational Designer
(sqlmetal.exe in LINQ Preview) to generate a class that represents
the database with an appropriate object model.
LINQ to SQL is that it can generate objects known as projections
that contain only the fields you want to receive from a specific
query, not the entire row.
LINQ to SQL selects only the required fields and creates objects
that contain only the selected fields.
Introducing LINQ to SQL
Introducing LINQ to SQL
Building the Data Access Layer
The first step to using LINQ to SQL is to build a
DataContext.

Map the database


You will generate one Entity class per table. tables/stored procedures
to LinQ to SQL classes
Building the Data Access Layer
The next step will be to create a simple helper class.
DatabaseHelper takes care of configuration
management and initialization of the DataContent class.
DatabaseHelper reads the connection string from the
<connectionString> block in the web.config or
app.config file.
It also stores the ApplicationId for the ASP.NET
membership provider.
Building the Data Access Layer
Data models:
Whenever you create a new application using an ASP.NET membership,
ASP.NET creates an entry in the Aspnet_Applications table.
This ApplicationID is also used in the aspnet_users table to identify
which application a user belongs to.
The membership provider is built for hosting multiple applications in the
same database.
A problem with LINQ to SQL. If an entity travels through multiple tiers, then it
gets detached from the DataContext that created it.
LINQ to SQL requires that you attach the entity object before making changes
to it.
Inactive User and Related Data
Identify inactive user and related data:
Challenges occur when an Ajax web portal cleans unused
data that is generated by anonymous users who do not
return.
Every first visit creates one anonymous user, a page
setup, widgets, etc.
If the user doesnt return, that information remains in the
database permanently.
Inactive User and Related Data
This is a huge cleanup operation based on thousands of daily
users:
Find out the users that are old enough to be discarded and are anonymous.
Find out the pages the user has.
Delete all of the widget instances on those pages.
Delete those pages.
Remove rows from child tables related to aspnet_users like aspnet_profile,
aspnet_UsersInRoles, and aspnet_PersonalizationPerUser.
Remove rows for users to be deleted.
Remove the users from aspnet_users.
Windows Workflow Foundation
Windows Workflow Foundation (WF), included in .NET 3.0, provides the
programming model, engine, and tools for quickly building workflow-
enabled applications.
This allows creation of business model processes via flow chart
development.
WF consists of:
An activity model.
A workflow designer.
Workflow runtime.
Rules engine.

WF can be used in most applications as long as they are not complex.


Building the Business Layer Using WF
DashboardFacade provides a single entry point to the
entire business layer.
It provides easy-to-call methods that run workflows.
Getting a return object from a workflow is complicated.
The WorkflowHelper.Init function initializes workflow
runtime for the ASP.NET environment.
Workflow runtime is initialized from the Application_Start
event in Global.asax.
Inside the WorkflowHelper, most of the work is done in the
ExecuteWorkflow function.
Building the Business Layer Using WF
DashboardFacade calls this function to run a workflow,
which:
Executes the workflow synchronously.
Passes parameters to the workflow.
Gets output parameters from the workflow and returns
them.
Handles exceptions raised in the workflow and passes to the
ASP.NET exception handler.

S-ar putea să vă placă și