Architecting the Data Layer with EF in the Enterprise
1. EF in the Enterprise:
Architecting the Data Layer
Julie Lerman
thedatafarm.com
@julielerman
Boston Code Camp March 2013
2. Julie Lerman
consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
contact
jlerman@theDataFarm.com
www.thedatafarm.com
blog
theDataFarm.com/blog
twitter
@julielerman
Julie Lerman, Boston Code Camp March 2013
book web site
LearnEntityFramework.com
3. My (best laid) plan
Where EF fits into your architecture
Repository Pattern(s)
Benefits of a Unit of Work
Bounded DbContext for small models
Unit Testing with Entity Framework
Julie Lerman, Boston Code Camp March 2013
4. Demo
Ware
Julie Lerman, Boston Code Camp March 2013
5. UI
Logic
LINQ
Database
Julie Lerman, Boston Code Camp March 2013
6. Separation of Concerns
Extensible
Adaptable Sensible
Testable
Maintainable
Julie Lerman, Boston Code Camp March 2013
7. UI
Service Layer
Bus Layer
Tests
Repository/Unit of Work
LINQ
Tests
Data Layer EF
Database
Julie Lerman, Boston Code Camp March 2013
9. “bounded context”
Delimits the applicability of a particular
model.
BOUNDING CONTEXTS gives team
members
a clear and shared understanding of
what has to be consistent
and
what can develop independently.
Julie Lerman, Boston Code Camp March 2013
13. Repository Essential:
Encapsulate
Redundant
Data Access
Code
Julie Lerman, Boston Code Camp March 2013
14. UI
Service Layer
Bus Layer
Tests
Repository/Unit of Work
LINQ
Tests
Data Layer EF
Database
Julie Lerman, Boston Code Camp March 2013
15. Basic Repository
Get
Remove Store
Send
Julie Lerman, Boston Code Camp March 2013
to
DB
16. Many variations…
One repo
One repo per
per type? object
graph?
Read
repos?
Write One repo
repos? per
context?
Julie Lerman, Boston Code Camp March 2013
17. Get
Get
Re
move
Store
Remove Store
Send
to DB
Send
to DB
Get Customer
Rem
Store Aggregate Orders
ove
Root
Send
to
DB
Julie Lerman, Boston Code Camp March 2013
Addresses
18. Testing with EF in the Mix
Integration/ •EF only or Database?
Interaction •Using database:
Tests DropCreateDatabaseAlways
•No EF involved: Inconsequential
Unit Tests •EF in the way:
Abstraction/Interfaces
Julie Lerman, Boston Code Camp March 2013
19. Testability
Classes System.Data
Fake .Entity
DbSet
Fake
Fake
Context & DataA Metadata &
Context & Data B DbContexts
Tests
Julie Lerman, Boston Code Camp March 2013 Unit of Work
UI
20. Julie Lerman
consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
contact
jlerman@theDataFarm.com
www.thedatafarm.com
blog
theDataFarm.com/blog
twitter
@julielerman
Julie Lerman, Boston Code Camp March 2013
book web site
LearnEntityFramework.com