Given at Oredev 2013 (Nov 2013 in Malmo Sweden). This presentaiton is about the intersection of Entity Framework (EF ) and Domain Driven Design (DDD) and gives pointers about *not* worrying about EF when implementing your domain in code and what you can expect when it's time to implement the persistence layer. There is a video of me giving this presentation on Vimeo at http://vimeo.com/78893724
18. EF & DDD Value Objects
EF Complex Types
• No Identity Key
• Property of Entity/other Complex Type
• Maps to columns of parent
entity/entities
DDD Value Object
• No Identity Key
• Immutable
• Equality compares all values
• No Side-Effects
19. Do You Need a Persistence
Model?
Entity Framework/Queries/Commands
Domain
Model
Persistence
Model
Payments
Invoices
Customers
DB Mappings,
DB concerns,
Follow EF rules
Domain
Model
Payments
Credit
Invoice
Payee
Payments
Credit
Invoice
Payee
Credits
23. Testing with EF in the Mix
• EF only or Database?
• Using database:
DropCreateDatabaseAlways
Integration/
Tests
• No EF involved: Inconsequential
• EF in the way:
Abstraction/Interfaces
Unit Tests
24. Replace EF Behavior in Tests
Mocking Frameworks
• Learning Curve
• Magic
• DbSets are not always supported
Roll Your Own Fakes
• Learning Curve
• More coding effort
• Educational
EF6 More Easily Supports Mocks
• DbSet has new features
• Chose not to enhance IDbSet to match
• Instead, DbSet is more mockable
• Protected constructor has no ties to DbContext
25. DDD += EF
• Focus on Domain
• Map to persistence later
• EF can resolve most DDD patterns
• Some tweaks may be required
• Consider separate persistence model in more complex scenarios
28. Resources
• Coding for Domain-Driven Design: Tips for Data-Focused Devs Part 1-3
MSDN Mag Data Points Column August 2013, Sept 2013, October 2013
• Pluralsight On-Demand Training: pluralsight.com
• MSDN Developer Center: msdn.com/data/ef
• EF Team: blogs.msdn.com/adonet
• LearnEntityFramework.com
• Programming Entity Framework: DbContext
• by Julie Lerman and Rowan Miller, O’Reilly Media, Feb 22 2012
• Domain Driven Design By Eric Evans, Addison-Wesley, 2004
• Implementing Domain Driven Design, A-W, Vaughn Vernon, 2013
• domaindrivendesign.org
29. consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
contact
jlerman@theDataFarm.com
www.thedatafarm.com
blog
theDataFarm.com/blog
twitter
@julielerman
book web site
LearnEntityFramework.com
Contact Info
(40% off at
O’Reilly
booth)
Focus on repo on this slide, then use code samples to quickly show difference between code that uses context directly and code that uses a repository, also show unit of work encapsulating a transaction possibly sharing reposPoints to make about demo ware…controller has direct access to /dependeny on EF. Need to know ins and outs of EF, linq to EF etc to get and update the data you want. Changes to data access logic may have direct impact on controller code which then needs to be modified. That may impact the UI code. That’s just the beginning of the problems.