The Entity Framework 4.0 and ASP.NET Web Forms - Getting Started.pdf
(
5449 KB
)
Pobierz
The Entity Framework 4.0 and
ASP.NET Web Forms: Getting Started
Tom Dykstra
Summary
: In this book, you'll learn the basics of using Entity Framework Database First
to display and edit data in an ASP.NET Web Forms application.
Category:
Step-By-Step
Applies to
: ASP.NET 4.0, ASP.NET Web Forms, Entity Framework 4.0, Visual Studio 2010
Source
: ASP.NET site
(
link to source content
)
E-book publication date
: June 2012
Copyright © 2012 by Microsoft Corporation
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means
without the written permission of the publisher.
Microsoft and the trademarks listed at
http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx
are trademarks of the
Microsoft group of companies. All other marks are property of their respective owners.
The example companies, organizations, products, domain names, email addresses, logos, people, places, and events
depicted herein are fictitious. No association with any real company, organization, product, domain name, email address,
logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without any
express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will
be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
2
Contents
Introduction ............................................................................................................................................................................................7
Creating the Web Application...............................................................................................................................................8
Creating the Database........................................................................................................................................................... 11
Creating the Entity Framework Data Model ................................................................................................................. 14
Exploring the Entity Framework Data Model ............................................................................................................... 20
The EntityDataSource Control ...................................................................................................................................................... 28
Adding and Configuring the EntityDataSource Control .......................................................................................... 28
Configuring Database Rules to Allow Deletion........................................................................................................... 33
Using a GridView Control to Read and Update Entities .......................................................................................... 37
Revising EntityDataSource Control Markup to Improve Performance .............................................................. 41
Displaying Data from a Navigation Property ............................................................................................................... 43
Using a DetailsView Control to Insert Entities ............................................................................................................. 45
Displaying Data in a Drop-Down List.............................................................................................................................. 46
Filtering, Ordering, and Grouping Data.................................................................................................................................... 50
Using the EntityDataSource "Where" Property to Filter Data................................................................................ 51
Using the EntityDataSource "OrderBy" Property to Order Data .......................................................................... 52
Using a Control Parameter to Set the "Where" Property........................................................................................ 53
Using the EntityDataSource "GroupBy" Property to Group Data......................................................................... 57
Using the QueryExtender Control for Filtering and Ordering ............................................................................... 59
Using the "Like" Operator to Filter Data ........................................................................................................................ 62
Working with Related Data ........................................................................................................................................................... 64
Displaying and Updating Related Entities in a GridView Control ........................................................................ 65
Displaying Related Entities in a Separate Control...................................................................................................... 70
Using the EntityDataSource "Selected" Event to Display Related Data............................................................. 76
Working with Related Data, Continued.................................................................................................................................... 80
Adding an Entity with a Relationship to an Existing Entity..................................................................................... 81
Working with Many-to-Many Relationships ................................................................................................................ 84
Implementing Table-per-Hierarchy Inheritance.................................................................................................................... 91
Table-per-Hierarchy versus Table-per-Type Inheritance ........................................................................................ 91
Adding Instructor and Student Entities .......................................................................................................................... 92
3
Mapping Instructor and Student Entities to the Person Table.............................................................................. 97
Using the Instructor and Student Entities ..................................................................................................................... 99
Using Stored Procedures..............................................................................................................................................................106
Creating Stored Procedures in the Database.............................................................................................................106
Adding the Stored Procedures to the Data Model..................................................................................................110
Mapping the Stored Procedures.....................................................................................................................................111
Using Insert, Update, and Delete Stored Procedures .............................................................................................116
Using Select Stored Procedures ......................................................................................................................................117
Using Dynamic Data Functionality to Format and Validate Data.................................................................................119
Using DynamicField and DynamicControl Controls ................................................................................................119
Adding Metadata to the Data Model............................................................................................................................124
The ObjectDataSource Control ..................................................................................................................................................129
Business Logic and Repository Classes.........................................................................................................................129
Updating the Database and the Data Model.............................................................................................................131
Adding a Relationship to the Database .......................................................................................................................131
Adding a View to the Database.......................................................................................................................................134
Updating the Data Model..................................................................................................................................................135
Using a Repository Class and an ObjectDataSource Control ..............................................................................140
Adding Insert and Delete Functionality........................................................................................................................144
The Attach Method...............................................................................................................................................................146
The SaveChanges Method.................................................................................................................................................147
Retrieving Instructor Names to Select When Inserting..........................................................................................147
Creating a Page for Inserting Departments................................................................................................................147
Adding Update Functionality............................................................................................................................................151
Adding a Business Logic Layer and Unit Tests.....................................................................................................................156
Creating a Repository Interface.......................................................................................................................................156
Creating a Business-Logic Class ......................................................................................................................................158
Creating a Unit-Test Project and Repository Implementation............................................................................163
Creating Unit Tests ...............................................................................................................................................................166
Adding Business Logic to Make a Test Pass...............................................................................................................169
Handling ObjectDataSource Exceptions ......................................................................................................................173
Sorting and Filtering.......................................................................................................................................................................178
4
Plik z chomika:
wiklef8
Inne pliki z tego folderu:
802.11_wireless_networks_the_definitive_guide_second_edition.pdf
(9934 KB)
beginning_sharepoint_designer_2010.pdf
(18859 KB)
Claims-based Identity Second Edition device.pdf
(19784 KB)
5TSSSISU_SQL_Server_2012.pdf
(659 KB)
AGM_Application_Virtualization_(App-V)_5.0.pdf
(1605 KB)
Inne foldery tego chomika:
book
books 1
Complete IT Books Pack
Exams
Kursy
Zgłoś jeśli
naruszono regulamin