Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
15Activity
0 of .
Results for:
No results containing your search query
P. 1
Entity Framework Learning Guide

Entity Framework Learning Guide

Ratings: (0)|Views: 742|Likes:
Published by Miroslav Novta
This is a very good reference user guide for Microsoft Entity framework as a learning book for beginners and reference for experienced users
This is a very good reference user guide for Microsoft Entity framework as a learning book for beginners and reference for experienced users

More info:

Published by: Miroslav Novta on Jul 16, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/29/2013

pdf

text

original

 
 
If you like or dislike my work or have suggestions, send me an email atzeeshanjhirani@gmail.com. I would love to hear your feedback!
 
1.
 
Introduction to Entity Framework ................................................................................ 4
 
1.1
 
Generating Entity Data Model from the designer ............................................................... 4
 
1.2
 
Loading csdl,msl,ssdl schema files ................................................................................... 21
 
1.3
 
Implementing IPOCO with Entity Framework ................................................................... 26
 
2.
 
Modeling Entities ....................................................................................................... 36
 
2.1
 
Self Referencing Table ..................................................................................................... 36
 
2.1.1
 
Self Referencing Table with Many to Many Association ................................................................. 36
 
2.1.2
 
Self Referencing entity with Table per Hierarchy ........................................................................... 41
 
2.1.3
 
Using Common CTE with Self Referencing Entity ............................................................................ 47
 
2.1.4
 
Many To Many association on Self referencing entity .................................................................... 52
 
2.2
 
Many to Many Mapping .................................................................................................. 55
 
2.2.1
 
Many To Many Mapping Walkthrough ........................................................................................... 56
 
2.2.2
 
Retrieving Link table for Many to Many Relation ........................................................................... 61
 
2.2.3
 
Implementing Many to Many relationship as two 1 to Many relationship .................................... 62
 
2.2.4
 
Modeling two 1 to many relationship as Many to Many relationship ............................................ 70
 
2.2.5
 
Mapping Many to Many table as 2 Many to Many Associations .................................................... 76
 
2.3
 
Entity Splitting ................................................................................................................. 86
 
2.3.1
 
Entity Splitting with three tables..................................................................................................... 86
 
3.
 
Eager and Lazy Loading entities and Navigation properties ....................................... 91
 
3.1
 
Using Include to load Child Entities in Entity Framework ................................................. 91
 
3.1.1
 
Loading EntityRef and EntityCollection Using Include .................................................................... 92
 
3.1.2
 
Using Include with Query Path to load related entities .................................................................. 94
 
3.1.3
 
Eagerly loading navigation properties on derived Types ................................................................ 97
 
3.1.4
 
Using Include with self referencing entity .................................................................................... 100
 
 
3.1.5
 
Using Include with Many to Many association ............................................................................. 104
 
3.1.6
 
Using Include at entity client layer ................................................................................................ 107
 
3.1.7
 
Common Pitfalls with Include operator ........................................................................................ 108
 
3.2
 
Using Load Operator to Lazy Load Collection and entity reference ................................. 113
 
3.3
 
CreateSourceQuery ....................................................................................................... 120
 
3.3.1
 
CreateSourceQuery to filter associations ..................................................................................... 120
 
3.3.2
 
CreateSourceQuery to Execute Aggregate operation on Child collections ................................... 122
 
3.3.3
 
CreateSourceQuery to retrieve specific derived type from entity collection ............................... 123
 
3.4
 
Relationship Span .......................................................................................................... 125
 
3.4.1
 
Taking Advantage of Relationship Span ........................................................................................ 125
 
3.4.2
 
Preventing Relationship span by using MergeOption.NoTracking ................................................ 131
 
4.
 
Views ....................................................................................................................... 134
 
4.1
 
QueryView .................................................................................................................... 134
 
4.1.1
 
Using QueryView To exclude columns and add computed columns ............................................ 135
 
4.1.2
 
Using QueryView to filter collection ............................................................................................. 139
 
4.1.3
 
QueryView to map Many to Many Relationship with PlayLoad ................................................... 143
 
4.2
 
DefiningQuery ............................................................................................................... 155
 
4.2.1
 
Operators supported on QueryView ............................................................................................. 157
 
4.2.2
 
Mapping Foreign Key column to Multiple Associations Using DefiningQuery .............................. 158
 
4.2.3
 
Creating Dummy Defining Query to map stored procedure results ............................................. 171
 
4.2.4
 
Creating Read-only Calculated Properties using Defining Query .................................................. 175
 
4.2.5
 
Using DefiningQuery to map multiple associations to foreign key ............................................... 179
 
5.
 
Inheritance ............................................................................................................... 185
 
Basics of Inheritance ................................................................................................................................... 185
 
5.1.1
 
Table per Type Walkthrough ......................................................................................................... 187
 
5.1.2
 
Table per Hierarchy (Walkthrough) .............................................................................................. 193
 
5.1.3
 
Extending Table per Type with Table per Hierarchy ..................................................................... 199
 
5.1.4
 
Extending Table per Hierarchy with Table per Type ..................................................................... 211
 
5.1.5
 
Creating additional hierarchy for TPT using QueryView ............................................................... 220
 
5.1.6
 
Optimizing QueryView for Inheritance ......................................................................................... 232
 
5.1.7
 
Overriding Conditions for nested inheritance............................................................................... 235
 
5.1.8
 
Applying Conditions on Base Entity .............................................................................................. 242
 
5.1.9
 
Using Abstract entity with no table Mapping in TPH .................................................................... 245
 
5.1.10
 
Applying IsNull condition to Table per Hierarchy .................................................................. 250
 
5.1.11
 
Creating Many To 1 Association on Derived Entity ................................................................ 255
 
5.1.12
 
Table per Concrete Type ........................................................................................................ 263
 
5.1.13
 
Mapping Column Used as a Discriminator ............................................................................. 268
 
5.1.14
 
Mapping Table per Type to Foreign Key column ................................................................... 271
 
5.1.15
 
Using QueryView with TPH to create additional inheritance layer ....................................... 279
 
5.1.16
 
Sharing Audit Fields across entities using TPC ....................................................................... 288
 
5.1.17
 
Creating Association between Two Table Per Type entities .................................................. 293
 
5.1.18
 
Creating Associations on Derived Entities using Table per Hierarchy ................................... 298
 
 
5.1.19
 
Table per Hierarchy and Table per Type Hybrid .................................................................... 305
 
5.1.20
 
Using multiple conditions for Table per Hierarchy ................................................................ 310
 
5.2
 
Linq To Sql ..................................................................................................................... 313
 
5.2.1
 
Table per type inheritance using Linq to Sql ................................................................................. 313
 
5.2.2
 
Table per Hierarchy With Enum Using Linq To Sql ........................................................................ 325
 
6.
 
Working with Objects ............................................................................................... 332
 
6.1
 
Using auto-generated Guids as entity key ...................................................................... 332
 
6.2
 
Reading xml data type columns using EF ........................................................................ 337
 
6.3
 
How does StoreGeneratedPattern work ........................................................................ 341
 
6.4
 
Exposing EntityCollection and EntityReference properties on an entity ......................... 344
 
6.5
 
Monitoring collection changes (Add and Remove) ......................................................... 352
 
6.6
 
When does Association changed Event get fired. ........................................................... 360
 
6.7
 
Complex Types .............................................................................................................. 368
 
6.8
 
Accessing derived types from ObjectContext ................................................................. 376
 
7.
 
Improving Entity framework performance ............................................................... 379
 
7.1
 
Delay Loading Expensive Fields on a Table ..................................................................... 379
 
7.1
 
GetObjectByKey vs First Operator ................................................................................. 383
 
7.2
 
Retrieving read-only entities using MergeOption.NoTracking ........................................ 387
 
7.3
 
Compiled Queries .......................................................................................................... 396
 
7.4
 
Detaching entities returned from stored procedure ....................................................... 403
 
7.5
 
Improving loading time by generating store views ......................................................... 405
 
8.
 
Inserting, Updating and Deleting entities and associations ...................................... 410 
 
8.1
 
Assigning foreign key value without loading entity reference ........................................ 410
 
9.
 
Querying with Linq to entities .................................................................................. 414
 
9.1
 
How to do in Clause Query ............................................................................................ 414
 
9.2
 
Returning subset of collection using Paging ................................................................... 418
 
10.
 
Concurrency and Transactions .................................................................................. 424
 
10.1.1
 
Concurrency with Table per Type .......................................................................................... 424
 
11.
 
Consuming Stored Procedures .................................................................................. 428 
 
11.1.1
 
Stored Procedure Returning entities ..................................................................................... 428
 
11.1.2
 
Stored Procedure Returning Scalar Types ............................................................................. 438
 
11.1.3
 
Stored Procedure Returning Anonymous Type ..................................................................... 441
 
11.1.4
 
Stored Procedure with Command Text Option ..................................................................... 445
 

Activity (15)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
PeraMali89 liked this
draganastek68 liked this
Midhat Krilic liked this
dauben liked this
rakeshkeny liked this
iamkvp liked this
test21212 liked this
originales liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->