Hands On Lab: Building Your First Semantic Model with the ADO ...

taupesalmonInternet and Web Development

Oct 21, 2013 (4 years and 17 days ago)

75 views




Hands
-
On Lab

Building Your First Semantic Model with the
ADO.NET Entity Framework



Lab version:



1.0.0

Last updated:


10/21/2013





CONTENTS

OVERVIEW

................................
................................
................................
................................
...................

3

EXERCISE 1: DELIVERI
NG A

WCF DATA SERVICE

................................
................................
................

4

Task 1


Creating an ASP.NET Web Application

................................
................................
....................

4

Task 2


Creating an ADO.NET Entity Data Model

................................
................................
................

5

Task 3


Refining the Design of the Data Model

................................
................................
...................

7

Task 4


Creating a WCF Data Service

................................
................................
................................
...

8

Task 5

Exploring the Data Service

................................
................................
................................
.......

9

Task 6

Finishing Up

................................
................................
................................
............................

11

SUMMARY

................................
................................
................................
................................
..................

11




Overview

This
lab creates an ADO.NET Entity Data Model and exposes it via a WCF Data Service.

Note:
Before you
start
with this exercise you must ensure that your machine meets the system
requirements detailed in the
next section. Additionally, you must complete the setup steps

described in
the next section.


Objectives

The objective
s

of this exercise are to:



Create an ADO.NET Entity Data Model



Expose the ADO.NET Entity Data Model as a data service



Consume the data ser
vice using Internet Explorer


System Requirements

You must have

installed

the following items to complete this lab:



Microsoft SQL Server 2008 R2 Express or higher
:



Database Engine



SQL Server AdventureWorks2008 R2 sample databases



AdventureWorks Data Warehouse 2008R2



Visual Studio 2010

SP1
:



Visual C#


Setup

All the requisites for this lab are verified us
ing the
Configuration Wizard
. To make sure that everything is
correctly configured, follow these steps
.

Note:
To perform the setup steps you need to run the scripts in a command window with
administrator privileges
.


1.

Launch the
Configuration Wizard

for this lab by double
-
clicking the
Dependencies.dep

file
located under the
Source
\
Setup

folder of this lab. Install any pre
-
requisites that are missing
(rescanning if necessary) and complete the wizard.


Cleanup

There is no need to cleanup if you intend
to continue the sequence of labs in this training kit.

1.

To remove the
data service and restore the original state of the
AdventureWorksDW2008R2

database
, execute
the
Cleanup.cmd

script located under the
Setup

folder in the
Source

folder
of this lab
.


Exercises

This Hands
-
On Lab comprise
s

the following exercise:

1.

Delivering a
WCF
Data Service


Estimated time to complete this lab:
15

minutes
.


Exercise 1: Delivering
a WCF

Data
Service

In this exercise,
you will commence by creating an ASP.NET Web application. In the web project you will
add an ADO.NET Entity Data Model that will include a single entity based on a view from the
AdventureWorksDW2008R2

database. The view,
vDateFeed
, will expose date data to

support self
-
service Business Intelligence, specifically for users creating BI Semantic Models with the PowerPivot
Add
-
in for Excel. Finally, you will expose the Entity Data Model as a WCF Data Service.

Task 1


Creating an ASP.NET Web Application

In this

task, you
will
create an empty ASP.NET web application that will
be used to
host
the

data service.

1.

Open
Visual Studio

from
Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual
Studio 2010
.

2.

If prompted to choose default environment settin
gs (required the first time Visual Studio is
launched), select
Visual C# Development Settings
, and then click
Start Visual Studio
.

3.

To create the project, on the
File

menu, select
New | Project
.

4.

In the
New Project

window, in the
Installed Templates

pane (lo
cated on the left), inside the
Visual C#

group,
select

Web
.

5.

Select the
ASP.NET Empty Web Application

template.


Figure 1

Selecting the Project Template


6.

In the
Name

box, replace the text with
AWFeed
s
.

7.

To set the project location, click
Browse
.

8.

In the
Project Location

window, navigate to the
Source

folder for this lab, and then click
Select
Folder
.

9.

In the
New Project

window, click
OK
.

10.

When the project is created, to close the
Default.aspx

file (which opened automatically), on the
File

menu, select
Close
.

11.

To save the solution,
on the
Solution Explorer

select the project
AWFeeds

and
on the
File

menu, select
Save AWFeeds
.


Task 2


Creating
an

ADO.NET Entity Data Model

In this task, you
will
create an ADO.NET Entity Data Model that consists of the
vDateFeed

view from the
AdventureWorksDW2008R2

database.

1.

In
Solution Explorer

(located on the right), right
-
click the
AWFeeds

project

(not the
AWFeeds

solution)
, and then select
Add | New Item
.


Figure 2

Locating

the AWFeeds Project


2.

In the
Add New Item

window, in the
Installed Templates

pane, select
Data
.

3.

Select the
ADO.NET Entity Data Model

template.

4.

In the
Name

box, replace the text with
AWModel
, and then click
Add
.

5.

In the
Entity Data Model Wizard
,
in

the
Choose Model Contents

step
, ensure
Generate
Fr
om Database

is selected, and then click
Next
.

6.

In the
Choose Your Data Connection

step, click
New Connection

to define a connection to
the database.

7.

In the
Choose Data Source

window, in the
Data Source

list, select
Microsoft SQL Server
, and
then click
Conti
nue
.

8.

In the
Connection Properties

window, in the
Server Name

box, type
SqlServerTrainingKitAlias
.

9.

In the
Select or Enter a Database Name

dropdown list, select
AdventureWorksDW2008R2
,
and then click
OK
.


Figure 3

Configuring the Data Source Connection


10.

In the
Entity Data Model Wizard

window, click
Next
.

11.

In the
Choose Your Database Objects

step, expand
Views
,
check

vDateFeed
, and then click
Finish
.

12.

To save the entire solution, on the
File

menu, select
Save All
.


Task 3


Refining

the Design of the Data Model

In this task,
you
will modify the design of the entity data model

by providing a friend
ly

name and
description for the entity
. As the
vDateFeed

entity is based on a view
,

the
wizard

assumes any column
that ends with the word
K
ey

forms part of the entity (primary) key. You will configure the correct key
definition in this task.

1.

In the
Entity Data Model

designer (which was opened on completion of the wizard), select the
vDateFeed

entity.

2.

In the
Properties

w
indow

(located in the b
ottom right corner)
, configure the properties based
on the following:

Note:

If the
Properties

window is not open, on the
View

menu,
select

Properties Window
.


Property

Value

Documentation | Summary

Corporate date data to support self
-
service BI

Entity
Set Name

CorporateDate


3.

In the entity data model designer, inside the
vDateFeed

entity,

then
inside the
Properties

group, select the
Date

property.


Figure 4

Selecting the Date Property


4.

In the
Properties

w
indow, modify the
Entity Key

property

to

False
.

5.

Repeat the last two steps for the
MonthOfYearKey
,
CalendarQuarterOfYearKey

and
CalendarYearKey

properties.

6.

To save the entire solution, on the
File

menu, select
Save All
.


Task 4


Creat
ing

a

WCF Data Service

In this task,
you will add a WCF D
ata
S
ervice

to the project

and configure it to expose all entities in the
AWModel

entity data model as a read
-
only feeds.

1.

In
Solution Explorer
, right
-
click the
AWFeeds

project, and then select
Add | New Item
.

2.

In the
Add New Item

window, in the
Installed Templates

pane,
select

Web
, and then s
elect the
WCF Data Service

template.

3.

In the
Name

box, replace the text with
AWService
, and then click
Add
.

4.

In the
AWService.svc.cs

item

(which opened automatically)
, in the public class declaration,
replace the
TODO

comment wit
h
Adventure
WorksDW2008R2Entities
.


Figure 4

Completing the Class Declaration


5.

Verify that t the line of code looks like the following.

C#

public class AWService : DataService<AdventureWorksDW2008R2Entities>


6.

To set the access rules, inside the
InitializeS
ervice

method, unc
omment the third commented
line, and then replace
MyEntityset

with an asterisk (*).

7.

Verify that t the line of code looks like the following.

C#

config.SetEntitySetAccessRule(
"
*
"
,

EntitySetRights.AllRead);


8.

To save the entire solution, on
the
File

menu, select
Save All
.


Task
5


Explor
ing

the Data Service

In this task,
you
will
explore the data service and modify the URL to retrieve specific feed data.

1.

In
Solution Explorer
, right
-
click the
AWService.svc

item, and then select
Set As

Start Page
.

2.

On the
Debug

menu, select
Start
Without
Debugging
.

3.

When the
Internet Explorer

window opens, review the URL to the data service.

Note:

The

AWService.svc

returns the ATOM service document. Notice the
CorporateDate

feed
embedded in the

service
do
cument.


4.

In the
Internet Explorer

window, to request the data feed, modify the URL by appending
CorporateDate
, and then press
Enter
.

URL

http://localhost
/AWService.svc/CorporateDate


Note:

Your

URL will include a port number also (for example, localhost:12
161).

Also, b
y default
,

Internet Explorer

displays the feed using a feed reading view.


5.

To disable the feed reading view, on the
Tools

menu, select
Internet Options
.


Figure 5

Identifying the Tools Menu


6.

In the
Internet Options

window, on the
Content

tab, in the
Feeds

and Web Slices

group, click
Settings
.

7.

In the
Feed
and Web Slice
Settings

window, in the
Advanced

group, uncheck the
Turn On Feed
Reading View

checkbox
, and then click
OK
.

8.

In the
Internet Options

window, click
OK
.

9.

To request the data feed

again,
in
Internet Explorer
,
position the cursor at the end of the URL,
and then press
Enter
.

10.

Notice

at the top of the document the feed entity and its child entities title and updated. In
particular notice the link entity’s
href

attribute which can be used to isolate a single entry from
the feed.
Notice also

the
entry

entity that

represents an instance of feed data. Inside the
content entity you will
find

the properties and values, including an attribute for each which
describes
the data type.

11.

To retrieve a single entry from the data feed, modify the URL by appending
(20050701)
, and
then press
Enter
.

URL

http://localhost
/AWService.svc/CorporateDate
(20050701)


12.

To retrieve a filtered set of entries for calendar year
2007

from the da
ta feed to the following,
and then press
Enter
.

URL

http://
localhost
/AWService.svc/CorporateDate?$filter=CalendarYearKey

eq 2007



Task
6


Finishing Up

In this task,
you
will
finish up by closing
all

open applications
.

1.

To stop debugging, c
lose the
Internet

Explorer

window.

2.

In
Visual Studio
, on the
File

menu, select
Exit
.


Summary

In this lab, you have
produced an ADO.NET Entity Model and exposed it as a
WCF D
ata
S
ervice. The data
in this data service is now available for consumption
by a wide range of app
lications including the
PowerPivot Add
-
in for Excel.