Tải bản đầy đủ (.pdf) (578 trang)

entity framework 4 in action

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (20.38 MB, 578 trang )

MANNING
Stefano Mostarda
Marco De Sanctis
Daniele Bochicchio
FOREWORD BY NOAM BEN-AMI
IN ACTION
www.it-ebooks.info
Entity Framework 4 in Action
www.it-ebooks.info
www.it-ebooks.info
Entity Framework 4
in Action
STEFANO MOSTARDA
MARCO DE SANCTIS
DANIELE BOCHICCHIO
MANNING
Shelter Island
www.it-ebooks.info
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity. 
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964
Email:
©2011 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.


Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
Manning Publications Co. Development editor: Sebastian Stirling
20 Baldwin Road Copyeditor: Andy Carroll
PO Box 261 Typesetter: Dottie Marsico
Shelter Island, NY 11964 Cover designer: Marija Tudor
ISBN 978-1-935182-18-4
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11
www.it-ebooks.info
v
brief contents
PART 1 REDEFINING YOUR DATA-ACCESS STRATEGY 1
1

Data access reloaded: Entity Framework 3
2

Getting started with Entity Framework 33
PART 2 GETTING STARTED WITH ENTITY FRAMEWORK 61
3

Querying the object model: the basics 63

4

Querying with LINQ to Entities 80
5

Domain model mapping 119
6

Understanding the entity lifecycle 151
7

Persisting objects into the database 176
8

Handling concurrency and transactions 203
PART 3 MASTERING ENTITY FRAMEWORK 225
9

An alternative way of querying: Entity SQL 227
10

Working with stored procedures 253
11

Working with functions and views 284
12

Exploring EDM metadata 296
13


Customizing code and the designer 322
www.it-ebooks.info
BRIEF CONTENTSvi
PART 4 APPLIED ENTITY FRAMEWORK 355
14

Designing the application around Entity Framework 357
15

Entity Framework and ASP.NET 378
16

Entity Framework and n-tier development 396
17

Entity Framework and Windows applications 423
18

Testing Entity Framework 447
19

Keeping an eye on performance 474
www.it-ebooks.info
vii
contents
foreword xvii
preface xxi
acknowledgments xxii
about this book xxiv
about the cover illustration xxix

PART 1 REDEFINING YOUR DATA-ACCESS STRATEGY 1
1
Data access reloaded: Entity Framework 3
1.1 Getting started with data access 4
1.2 Developing applications using database-like structures 5
Using datasets and data readers as data containers 5

The strong coupling problem 8

The loose typing problem 9

The performance problem 10
1.3 Using classes to organize data 10
Using classes to represent data 11

From a single class to the

object model 13
1.4 Delving deep into object/relational differences 15
The datatype mismatch 15

The association mismatch 16

The granularity mismatch 18

The inheritance mismatch 20

The identity mismatch 21

Handling the mismatches 22

www.it-ebooks.info
CONTENTSviii
1.5 Letting Entity Framework ease your life 23
What is O/RM? 23

The benefits of using Entity Framework 24

When isn’t O/RM needed? 26
1.6 How Entity Framework performs data access 26
The Entity Data Model 27

Object Services 29

Entity Client
data provider 31

LINQ to Entities 31

Entity SQL 32
1.7 Summary 32
2
Getting started with Entity Framework 33
2.1 Introducing the OrderIT example 34
2.2 Designing the OrderIT model and database 35
Bottom-up vs. top-down design 36

Customers and suppliers 37

Products 39


Orders 41
2.3 Structuring the application 42
Creating the assemblies 42

Designing entities using the database-
first approach 43

Designing relationships 50

Organizing
the generated code 52

The model-first approach in the
designer 54
2.4 A sneak peek at the code 55
Querying the database 55

Updating objects and reflecting
changes into storage 56
2.5 Summary 60
PART 2 GETTING STARTED WITH ENTITY FRAMEWORK 61
3
Querying the object model: the basics 63
3.1 One engine, many querying methods 64
3.2 The query engine entry point: Object Services 64
Setting up the connection string 66

Writing queries against
classes 70


LINQ to Entities queries vs. standard LINQ
queries 70

Retrieving data from the database 71

Understanding Identity Map in the context 72

Understanding
interaction between Object Services and Entity Client 74

Capturing the generated SQL 75

Understanding which entities
are returned by a query 76

When is a query executed? 77

Managing the database from the context 79
3.3 Summary 79
www.it-ebooks.info
CONTENTS ix
4
Querying with LINQ to Entities 80
4.1 Filtering data 81
Filtering data based on associations 82

Paging results 86

Retrieving one entity 87


Creating queries dynamically 89
4.2 Projecting results 90
Projecting with associations 92

Projections and object
tracking 95
4.3 Grouping data 96
Filtering aggregated data 100
4.4 Sorting 100
Sorting with associations 101
4.5 Joining data 102
4.6 Querying with inheritance 105
4.7 Using functions 107
Canonical functions 108

Database functions 109
4.8 Executing handmade queries 110
Working with parameters 111
4.9 Fetching 113
Eager loading 114

Lazy loading 115

Manual deferred
loading 116

Choosing a loading approach 118
4.10 Summary 118
5
Domain model mapping 119

5.1 The Entity Data Model 120
The Entity Data Model and Visual Studio designer 120
5.2 Creating consumable entities 123
Writing the entities 124

Describing entities in the conceptual
schema 127

Describing the database in the storage schema 130

Creating the mapping file 133
5.3 Defining relationships in the model 136
One-to-one relationships 136

One-to-many relationships 140

Many-to-many relationships 142

Some tips about
relationships 143
5.4 Mapping inheritance 144
Table per hierarchy inheritance 144

Table per type
inheritance 147
www.it-ebooks.info
CONTENTSx
5.5 Extending the EDM with custom annotations 149
Customizing the EDM 149
5.6 Summary 150

6
Understanding the entity lifecycle 151
6.1 The entity lifecycle 152
Understanding entity state 152

How entity state affects the
database 153

State changes in the entity lifecycle 153
6.2 Managing entity state 155
The AddObject method 155

The Attach method 157

The ApplyCurrentValues and ApplyOriginalValues methods 158

The DeleteObject method 159

The AcceptAllChanges
method 160

The ChangeState and ChangeObjectState
methods 161

The Detach method 161
6.3 Managing change tracking with ObjectStateManager 162
The ObjectStateEntry class 163

Retrieving entries 164


Modifying entity state from the entry 166

Understanding object
tracking 167

Understanding relationship tracking 170

Change tracking and MergeOption 174
6.4 Summary 175
7
Persisting objects into the database 176
7.1 Persisting entities with SaveChanges
177
Detecting dirty entities 177

Starting database
transactions 178

SQL code generation and execution 178

Database transaction commit or rollback 179

Committing
entities 179

Overriding SaveChanges 180
7.2 Persisting changed entities into the database 180
Persisting an entity as a new row 180

Persisting modifications

made to an existing entity 182

Persisting entity deletion 187
7.3 Persisting entities graphs 187
Persisting a graph of added entities 188

Persisting modifications
made to a graph 192

Persisting deletions made to a graph 196

Persisting many-to-many relationships 199
7.4 A few tricks about persistence 199
Handling persistence exceptions 199

Executing custom SQL
commands 200
7.5 Summary 202
www.it-ebooks.info
CONTENTS xi
8
Handling concurrency and transactions 203
8.1 Understanding the concurrency problem 204
The concurrent updates scenario 204

A first solution: pessimistic
concurrency control 205

A better solution: optimistic concurrency
control 206


The halfway solution: pessimistic/optimistic
concurrency control 207
8.2 Handling concurrency in Entity Framework 208
Enabling optimistic concurrency checking 208

Optimistic
concurrency in action 209

Catching concurrency
exceptions 213

Managing concurrency exceptions 214
8.3 Managing transactions 220
The transactional ObjectContext 222

Transactions and
queries 223
8.4 Summary 224
PART 3 MASTERING ENTITY FRAMEWORK 225
9
An alternative way of querying: Entity SQL 227
9.1 Query basics 228
9.2 Filtering data 230
Working with associations 230

Paging results 232
9.3 Projecting results 232
Handling projection results 233


Projecting with associations 235
9.4 Grouping data 237
9.5 Sorting data 239
Sorting data based on associations 239
9.6 Joining data 240
9.7 Querying for inheritance 240
9.8 Using query-builder methods 241
Chaining methods 242

Query-builder methods vs. LINQ to

Entities methods 243

Using parameters to prevent injection 244
9.9 Working with the Entity Client data provider 246
Connecting with EntityConnection 247

Executing queries

with EntityCommand 248

Processing query results with
EntityDataReader 248

Going beyond querying with Entity
Client 250
9.10 Summary 251
www.it-ebooks.info
CONTENTSxii
10

Working with stored procedures 253
10.1 Mapping stored procedures 254
Importing a stored procedure using the designer 254

Importing stored procedures manually 256
10.2 Returning data with stored procedures 258
Stored procedures whose results match an entity 258

Stored
procedures whose results don’t match an entity 261

Stored
procedures that return scalar values 266

Stored procedures

that return an inheritance hierarchy 268

Stored procedures

with output parameters 271
10.3 Embedding functions in the storage model 274
10.4 Updating data with stored procedures 275
Using stored procedures to persist an entity 276

Using stored
procedures to update an entity with concurrency 279

Persisting
an entity that’s in an inheritance hierarchy 280


Upgrading and
downgrading an entity that’s in an inheritance hierarchy 282

Executing stored procedures not connected to an entity 282
10.5 Summary 283
11
Working with functions and views 284
11.1 Views in the storage model: defining queries 285
Creating a defining query 285

Mapping stored procedures to
classes with complex properties 287
11.2 User-defined functions and scalar-valued functions 288
Scalar-valued functions 288

User-defined functions 290

User-defined functions and collection results 294
11.3 Summary 295
12
Exploring EDM metadata 296
12.1 Metadata basics 297
Accessing metadata 297

How metadata is internally organized 300
Understanding when metadata becomes available 301
12.2 Retrieving metadata 301
Understanding the metadata object model 302


Extracting
metadata from the EDM 303
12.3 Building a metadata explorer 306
Populating entities and complex types 306

Populating
functions 312

Populating containers 313

Populating
storage nodes 315
www.it-ebooks.info
CONTENTS xiii
12.4 Writing generic code with metadata 316
Adding or attaching an object based on custom annotations 317

Building a generic GetById method 319
12.5 Summary 321
13
Customizing code and the designer 322
13.1 How Visual Studio generates classes 323
Understanding template tags 324

Understanding
directives 325

Writing code 326
13.2 Customizing class generation 328
Understanding the available POCO template 328


Generating
user-defined and scalar-valued functions 329

Generating data-
annotation attributes 333

Extending classes through partial
classes 335
13.3 How Visual Studio generates database DDL 336
Choosing the workflow 337

Generating SSDL, MSL, and
DDL 338
13.4 Customizing DDL generation 339
Understanding the conceptual-to-storage template 340

Understanding the conceptual-to-mapping template 342

Understanding the storage-to-database script template 343
13.5 Creating designer extensions 344
How the property-extension mechanism works 344

Setting up the
project containing the extension 345

Creating the property
class 346

Creating the factory class 348


Creating the
manifest extension file 351

Installing, debugging, and
uninstalling the extension 352
13.6 Summary 353
PART 4 APPLIED ENTITY FRAMEWORK 355
14
Designing the application around Entity Framework 357
14.1 The application design process 358
14.2 A typical three-layer architecture 359
Filling the product list 359

Calculating order totals and saving
them to the database 361

Dealing with higher levels of
complexity 363
www.it-ebooks.info
CONTENTSxiv
14.3 Principles of domain-driven design 363
Entities 364

Value objects 365

Handling associations
correctly: domain roots and aggregates 367

Refining the

model 368
14.4 Retrieving references to a domain’s entities 371
Repositories at a glance 371

Implementing a repository 372

Getting a reference to a brand new entity 376
14.5 Summary 377
15
Entity Framework and ASP.NET 378
15.1 EntityDataSource, a new approach to data binding 379
A practical guide to data source controls 379

The EntityDataSource control in depth 380
15.2 Using Dynamic Data controls with Entity Framework 384
Registering the model 384

Working with data
annotations 386
15.3 The ObjectContext lifecycle in ASP.NET 388
The Context-per-Request pattern 389

Wrapping the
context 390

A module to handle the lifecycle 392

Using the repository in a page 393
15.4 Common scenarios involving ASP.NET and 
Entity Framework 393

15.5 Summary 395
16
Entity Framework and n-tier development 396
16.1 n-Tier problems and solutions 397
Tracking changes made on the client 397

Choosing data to be
exchanged between server and client 398

The serialization
problem 399
16.2 Developing a service using entities as contracts 400
Persisting a complex graph 403

Optimizing data exchanges
between client and server 404

Dealing with serialization in
WCF 405
16.3 Developing a service using DTOs 409
Persisting a complex graph 411
16.4 Developing a service using STEs 413
Enabling STEs 414

Inside an STE 415

Inside the
context 417

Using STEs 417


STE pros and cons 421
16.5 Summary 422
www.it-ebooks.info
CONTENTS xv
17
Entity Framework and Windows applications 423
17.1 An example application 424
17.2 Designing model classes for binding 425
Implementing INotifyPropertyChanged 425

Implementing
IEditableObject 426

Implementing IDataErrorInfo 429

Using a template to generate the binding code 431
17.3 Binding in Windows Forms applications 432
Showing orders 433

Showing data for the selected

order 434

Showing details of the selected order 436

Showing selected detail information 437

Adding code to


persist modifications 438

Taking advantage of binding
interfaces 440
17.4 Binding in WPF applications 441
Showing orders 441

Showing data for the selected

order 442

Showing selected order details 443

Showing
selected detail information 443

Adding code to persist
modifications 445
17.5 Summary 446
18
Testing Entity Framework 447
18.1 Unit tests at a glance 448
18.2 Writing a test suite in Visual Studio 2010 451
Testing a simple method 451

Advanced features of Microsoft’s
Unit Testing Framework 453
18.3 Isolating dependencies 455
Refactoring for testability 456


Using a mocking framework to
fake dependencies 458
18.4 Unit-testing the data access layer 461
A test infrastructure for a repository 462

Testing LINQ to
Entities queries 466
18.5 Testing the persistence and retrieval of an entity 470
18.6 Summary 473
19
Keeping an eye on performance 474
19.1 Testing configuration and environment 475
The performance test visualizer 476

Building the timer 476
19.2 Database-writing comparison 479
www.it-ebooks.info
CONTENTSxvi
19.3 Query comparisons in the default environment 481
19.4 Optimizing performance 484
Pregenerating views 484

Compiling LINQ to Entities
queries 487

Enabling plan caching for Entity SQL 490

Disabling tracking when it’s not needed 491

Optimizing stored

procedures 491
19.5 Summary 492
appendix A Understanding LINQ 494
appendix B Entity Framework tips and tricks 512
index 532
www.it-ebooks.info
xvii
foreword
I spend a lot of my time here at Microsoft thinking about complexity—and asking
myself lots of questions. My guess is that you do the same.
When we design code, we ask ourselves questions such as these: Can I make this
code more readable? Can I write this loop with fewer lines? Can I factor out behavior
into a separate class? Can I architect this system so that it is more cohesive?
When we design user interfaces, we ask similar questions: Are we asking the user to
make too many decisions? Did we lay out this UI in the clearest possible way? Can we
make error states clearer and easier to avoid?
When we design systems, we ask other questions: How many concepts must the
user learn? Do those concepts map to things the user knows and cares about? Does
everything hang together in a clear, sensible, consistent way?
I think about these things a lot. But first I’d like to answer another question that I
often get asked: Just how complicated is the Entity Framework? The answer is, that it
depends on what you want to do with it.
To see how simple the Entity Framework is, let’s spend five minutes making it jump
through a simple set of hoops. You’ll need Visual Studio 2010 (the Express editions
will work) and SQL Server (again, the Express editions will work just fine). In SQL
Server, create a database called “EntityFrameworkIsSimple.”
1 Launch Visual Studio 2010.
2 From the View menu, select Server Explorer.
3 In Server Explorer, add a new connection to your EntityFrameworkIsSimple
database.

www.it-ebooks.info
FOREWORDxviii
4 Create a new Console Application project, and call it EntityFrameworkIsSimple.
5 Right-click the project and select Add > New Item. In the Add New Item dialog
box, select ADO.NET Entity Data Model.
6 Click Add.
7 In the Entity Data Model Wizard that comes up, select Empty Model and click
Finish.
8 The entity designer will appear. Right-click in it and select Add > Entity.
9 In the Add Entity dialog box, set the entity name to Person. This will automati-
cally make the entity set People. (The set is the name of the collection to which
you’ll add new instances of the Person class.)
10 Click OK.
11 A new entity will appear. Right-click on the Properties bar inside of it and select
Add > Scalar Property. (Or just click on the Insert key.)
12 Rename the new property to FirstName.
13 Do this again, creating a new property called LastName.
14 Add another entity and call it Book.
15 To this new entity, add a property called Title.
16 Right-click the “Person” text in the Person entity and select Add > Association.
17 In the Add Association dialog box, change the Multiplicity on the Person end to
*

(Many)
, and change the Navigation Property value at right, from
Person
to
Authors
.
18 Click OK.

19 At this point, your model should look like this:
20 Now, right-click on an empty area of the designer and select Generate Database
from Model.
21 In the Generate Database Wizard that comes up, provide a connection to
your database. Because we’ve added a connection to the database at the
beginning of this walkthrough, it should show up in the drop-down list of
available connections.
22 Click Next.
23 The DDL for a database to hold your model shows up. Click Finish.
www.it-ebooks.info
FOREWORD xix
24 In the T-SQL editor that comes up, right-click and select Execute SQL. Provide
your local database information when asked to connect.
That’s it! We’ve got a model. We’ve got code. We’ve got a database. We’ve even got a
connection string in App.Config that the designer creates and maintains for you.
Let’s take this model for a test drive. Let’s name the model:
1 In the designer, right-click in an empty area of the canvas and select Properties.
2 In the Properties window, find the property called Entity Container Name and
change its value to
SimpleModel
.
3 In Program.cs, enter the following code into the body of the
Main
function:
//Create and write our sample data
using (var context = new SimpleModel()) {
var person1 = new Person() { FirstName = "Stefano", LastName="Mostarda" };
var person2 = new Person() { FirstName = "Marco", LastName="De Sanctis" };
var person3 = new Person() { FirstName = "Daniele", LastName="Bochicchio" };
var book = new Book() { Title = "Microsoft Entity Framework In Action"};

book.Authors.Add(person1);
book.Authors.Add(person2);
book.Authors.Add(person3);
context.People.AddObject(person1);
context.People.AddObject(person2);
context.People.AddObject(person3);
context.Books.AddObject(book);
context.SaveChanges();
}
//Query our sample data
using (var context = new SimpleModel()) {
var book = context.Books.Include("Authors").First();
Console.Out.WriteLine("The authors '{0}' are:", book.Title);
foreach(Person author in book.Authors) {
Console.Out.WriteLine(" - {0} {1}", author.FirstName, author.LastName);
}
}
Console.Read();
4 Compile and run this code. You should see the following output:
As you can see, we’ve created a system that issues queries and updates three different
tables. And not a single
join
statement in sight!
Of course, in the real world, we have many other concerns: How do we bind these
types to UI elements? How do we send and update them across distributed applica-
tion tiers? How do we handle concurrency, dynamic querying, and stored proce-
dures? While the Entity Framework may be simple to get started with, the real world
is not simple, and the Entity Framework has a host of features for dealing with real-
world situations.
www.it-ebooks.info

FOREWORDxx
Including an example like this may not be standard for a foreword to a book, but I
did so to show how easy getting started with Entity Framework is and also to show you
where this book comes in. Entity Framework 4 in Action will take you from handling
transactions to understanding how to deal with performance problems and using
ESQL to writing dynamic queries. And it will answer all of your questions along the
way—even ones you did not know you had!
I look forward to seeing what you will do with the Entity Framework and to hearing
what you want us to work on next. The authors are as excited as I am to show you what
is in store in the future!
NOAM BEN-AMI
PROGRAM MANAGER
ENTITY FRAMEWORK TEAM, MICROSOFT
www.it-ebooks.info
xxi
preface
Yatta, we did it! We wrote a book about Entity Framework! It’s not our first book, but
it’s the first one written in English and distributed worldwide. It was a great challenge,
but having the opportunity to spread the word about Entity Framework made it worth
the effort. Entity Framework is a great tool that speeds up the development of data
access code and that can save you days and days of coding. We know coding is our job,
but wouldn’t you prefer to be more productive while writing less and better code?
Entity Framework is a great O/RM tool that’s integrated into the .NET Framework,
meaning not only is it free, it’s also maintained and improved in each .NET Frame-
work release. The result is that it’s a great platform today, and tomorrow it will be an
outstanding one that will likely rule over all other O/RM platforms.
When we started planning this book, we had a clear idea in mind: we didn’t want to
create a reference book; we wanted to create a practical one. We wanted you to read
about real-world problems and learn real-world solutions. That’s why we developed an
example and improved on it throughout the book, avoiding common pitfalls and solv-

ing problems that you’d face on the job.
This is a book that we felt was missing among those that are available. You won’t find
a detailed description of all classes and properties here, but you’ll learn the best way to
use them and how to combine features to get the most out of Entity Framework. We’d
love to hear what you think about the book—you can reach us online at the various
addresses listed in the “About this book” section on page xxiv.
It took a long time to write this book, but now that it’s in your hands we can stop
spending endless nights in front of our monitors and finally sit down and spend more
time with our families.
Now it’s your turn. Enjoy the read, get your hands dirty, and have fun.
www.it-ebooks.info
xxii
acknowledgments
We can’t begin to count all the individuals who contributed to this book, each one
helping to improve the final product. All of them deserve a warm thank-you. While we
can’t name everyone here, we would like to offer special thanks to the following indi-
viduals who were particularly helpful:
Sebastian Stirling, our developmental editor at Manning—Sebastian worked with
us from the beginning and masterfully transformed a bunch of words and images into
an appealing book. Thank you.
Elisa Flasko, Program Manager of the Entity Framework team at Microsoft—Elisa
provided valuable information and routed our questions to the right person when she
didn’t have the answers. Without her, this book wouldn’t be so thorough. Thank you.
Noam Ben-Ami, Program Manager of the Entity Framework team at Microsoft—
Noam pointed us to the right solutions to many problems, and was especially helpful
when we were writing chapter 13. He also wrote the foreword to our book. Thank you.
Alessandro Gallo, an ASP Insider, consultant, and lead author of Manning’s
ASP.NET Ajax in Action—Alessandro didn’t contribute to the content of this book, but
he was the spark that started everything. Thank you.
Many individuals at Manning worked hard to make this book possible. First of all,

special thanks to Michael Stephens and Marjan Bace for believing in us. Others who
contributed are Karen Tegtmeyer, Mary Piergies, Maureen Spencer, Andy Carroll,
Dottie Marsico, Tiffany Taylor, Susan Harkins, Janet Vail, and Cynthia Kane.
Our reviewers deserve special mention—their suggestions were invaluable. We
thank Jonas Bandi, David Barkol, Timothy Binkley-Jones, Margriet Bruggeman,
Nikander Bruggeman, Gustavo Cavalcanti, Dave Corun, Freedom Dumlao, Rob
Eisenberg, Marc Gravell, Berndt Hamboeck, Jason Jung, Lester Lobo, Darren Neimke,
www.it-ebooks.info
ACKNOWLEDGMENTS xxiii
Braj Panda, Christian Siegers, Andrew Seimer, Alex Thissen, Dennis van der Stelt, and
Frank Wang. We’d also like to thank Deepak Vohra, our technical proofreader, for the
outstanding job he did reviewing the final manuscript during production.
Last, but not least, thank you, dear reader, for your trust in our book. We hope that
it will help you in your everyday job and will encourage you to fall in love with the
world of O/RMs.
In addition to the people we’ve already mentioned, there are others who are
important in our lives. Even if they didn’t contribute to the book, they contributed to
keeping us on track during the writing process. We acknowledge them below.
STEFANO MOSTARDA
I’d like to thank my wife Sara for her support and patience, as well as my family (yes,
the book is finally done!). Special thanks to my closest friends (in alphabetical order):
Federico, Gabriele, Gianni, and Riccardo. Of course, I can’t help mentioning Filippo,
who already bought a copy of the book. And a big thank-you to William and Annalisa
for their friendship and invaluable support.
My last words are for Marco and Daniele: thank you, guys!
MARCO DE SANCTIS
My thanks to Stefano and Daniele. It was a privilege to work with such smart and
funny guys. And thanks to the whole ASPItalia.com team. I’m proud to be a part of it.
Special thanks to my family, and to Barbara, for their support and their patience.
You have all my love.

DANIELE BOCHICCHIO
I would like to thank my wife Noemi for her support and patience, and for giving me
our beautiful sons, Alessio and Matteo. A big thank-you to my parents for letting me
play with computers when I was a kid, and to my family for supporting me.
A special thank-you to Stefano for the opportunity to help with this book. And
thanks to both Stefano and Marco for sharing their passion for Entity Framework. You
guys rock!
www.it-ebooks.info
xxiv
about this book
Entity Framework is the Microsoft-recommended tool to read and persist data inside a
relational database. With this software, Microsoft has entered the O/RM market with a
reliable product that significantly eases data access development.
This book will take you from the apprentice to the master level in the Entity
Framework technology. You can think of this book as a guided tour through Entity
Framework features and best practices. When you have finished reading Entity Frame-
work 4 in Action, you’ll be able to confidently design, develop, and deliver applications
that rely on Entity Framework to persist business data.
WHO SHOULD READ THIS BOOK?
This book was written for all Entity Framework developers, whether you develop small
home applications or the largest enterprise systems. Everything from home DVD
library applications to e-commerce solutions that interact with many heterogeneous
systems and store lots of information can benefit from Entity Framework, and this
book will show you how.
ROADMAP
This book will walk you through the creation of an application from scratch, and will
show you how to keep improving it with various Entity Framework features. This Entity
Framework tour will cover all of Framework’s features over the course of nineteen
chapters, grouped in four parts.
In part 1 we introduce the basics of the O/RM pattern and show you the funda-

mentals of Entity Framework as we create the foundation for an application.
Chapter 1 provides a high-level overview of the O/RM pattern and of the Entity
Framework components. By the end of this chapter, you’ll understand why O/RM
tools are so useful and how Entity Framework accomplishes its tasks.
www.it-ebooks.info

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×