3. Consulente, project manager e trainer dal 1996
Oltre 40 certificazioni Microsoft conseguite
Microsoft Certified Solutions Master – SharePoint
Focalizzato su .NET e SharePoint dal 2002
Autore di 10 libri su XML, SOAP, .NET,
LINQ e SharePoint
• Microsoft SharePoint 2013 Developer Reference, Microsoft Press
• Build Windows 8 Apps with Microsoft Visual C# and
Visual Basic Step by Step, Microsoft Press
• Microsoft SharePoint 2010 Developer Reference, Microsoft Press
Speaker alle principali conferenze IT
Chi sono
5. Official Object Relational Mapper (O/RM) from Microsoft
Included in .NET Framework
Available via NuGet, as well
Available for free on CodePlex
Source code available, ‘cause it is Open Source since EF6!
Great option for business-level data access solutions
But it is an O/RM … don’t expect great performances …
What’s Entity Framework
6. Developer workflows
New
Database
Existing
Database
Designer Centric Code Centric
Database First
Reverse engineer model in EF Designer
Classes auto-generated from model
Model First
Create model in EF Designer
Generate database from model
Classes auto-generated from model
Code First
Define classes and mapping in code
EF Power Tools provide reverse engineer
Code First
Define classes and mapping in code
Database created from code
Migrations apply model changes to database
7. Code First & EF Designer
Asynchronous query and save
Connection resiliency
Code-based configuration
Database command interception/logging
Performance improvements
Code First Only
Custom conventions
Insert, update, & delete stored procedures
What’s new in EF6 (1/4)
9. From the EF team
Nested entity types
Improved transaction Support
Multiple contexts per database
DbModelBuilder.HasDefaultSchema
Configurable migrations history table
Creating context with an open connection
Enums, spatial and better performance on .NET 4.0
Default transaction isolation level changed to READ_COMMITTED_SNAPSHOT
What’s new in EF6 (3/4)
10. From external contributors
Custom migrations operations
Improved warm up time for large models
Pluggable pluralization & singularization service
DbModelBuilder.Configurations.AddFromAssembly
DbSet.AddRange/RemoveRange
What’s new in EF6 (4/4)
12. You can create database from code
You can define custom conventions to “understand” your code-
based model
Main Goals
Override default conventions
Centralized code/data conventions
Avoid error prone configurations and repetitive tasks
Define company-level patterns
Code first with custom conventions
13. When you start from the code …
… code changes (often?!)
You can make EF keep track of changes
Defining migration paths from one version to another
Code Migrations will generate migration code for you
Code First Migrations
16. In case you want to be independent from the database schema
You can use stored procedures to manage data
Or you can even have already existing databases with stored
procedures
For custom business logic during save actions
If you have to support linked servers
You can now use Code First to map stored procedures to actions
You can leverage custom conventions, as well
Code First Stored Procedures
18. One of the smartest news of EF6!
To improve performances and scalability
To free-up UI threads
Not to parallelize tasks
Only one async query for each DbContext
Async queries
20. You can reuse already opened DbConnection instances
Finally!
Exception “Entity Connection can only be constructed with a closed DbConnection”
passed away …
Connection Resiliency
Automatic retry … very useful with Azure SQL Database
Managing Connections
21. You have always been able to use TransactionScope instances
around EF
Now you can also share DbTransaction
Not really useful if you have a “clean” architecture
But very useful in any other scenario …
Managed Transactions
23. Easy way to see what’s happening in SQL
To see how LINQ is converted to T-SQL
No need of SQL Server Profiler
Useful for debugging
Database Command Logging
24. Instead of <entityFramework>
Inherit a type from DbConfiguration
Automatic discovery of such a type
Automatic dependency injeciton
Then configure EF by code
For instance configure IDbCommandInterceptor
Code Based Configuration
26. Entity Framework Power Tools (Beta 4)
Allow to design a code first model
Allow to reverse engineer an existing DB
Procuding the “Code First” code … “after”
Reverse Engineering Existing DB
28. You should consider it …
And make a decision based on
• Performances
• Scalability
• Time to market
• Shared knowledge
• Total cost of management
Shall I use EF in real business solutions?
29. Don’t expect the very best performances you can ever achieve in your life
You have to pay the price for the infrastructure
But you have services back from the infrastructure
If you need super-fast solutions
Use custom ADO.NET code
And pay for it
• Implementation, maintenance, tooling, etc.
If you need “classic” performances
Give EF6 a chance …
Decouple code layer and be ready for any changes in the future
Moreover
30. Grazie a tutti per la partecipazione
Riceverete il link per il download a slide e demo via email nei
prossimi giorni
Per contattarmi
paolo@devleap.com
Grazie