Template designed by
Introduction to EF 6.x
Paolo Pialorsi
paolo@pialorsi.com
http://www.pialorsi.com/blog.aspx
brought to you by
Consulente, project manager e trainer dal 1996
Oltre 40 certificazioni Microsoft conseguite
Microsoft Certified Solutions ...
Entity Framework 6
Let’s start
Official Object Relational Mapper (O/RM) from Microsoft
Included in .NET Framework
Available via NuGet, as well
Available ...
Developer workflows
New
Database
Existing
Database
Designer Centric Code Centric
Database First
Reverse engineer model in ...
Code First & EF Designer
Asynchronous query and save
Connection resiliency
Code-based configuration
Database command inter...
Open Source!
http://entityframework.codeplex.com/
• Source code
• Nightly builds
• Issue tracking
• Feature specs
• Design...
From the EF team
Nested entity types
Improved transaction Support
Multiple contexts per database
DbModelBuilder.HasDefault...
From external contributors
Custom migrations operations
Improved warm up time for large models
Pluggable pluralization & s...
Usage scenarios
Let’s play with Entity
Framework 6
You can create database from code
You can define custom conventions to “understand” your code-
based model
Main Goals
Over...
When you start from the code …
… code changes (often?!)
You can make EF keep track of changes
Defining migration paths fro...
Code First Migrations
Explicit configuration
Data annotations
Custom conventions
Default conventions
Order of Precedence
In case you want to be independent from the database schema
You can use stored procedures to manage data
Or you can even h...
Code First
Stored Procedures
One of the smartest news of EF6!
To improve performances and scalability
To free-up UI threads
Not to parallelize tasks
On...
Async Queries
You can reuse already opened DbConnection instances
Finally! 
Exception “Entity Connection can only be constructed with a...
You have always been able to use TransactionScope instances
around EF
Now you can also share DbTransaction
Not really usef...
Connections
and Transactions
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 de...
Instead of <entityFramework>
Inherit a type from DbConfiguration
Automatic discovery of such a type
Automatic dependency i...
Code Based
Configuration
Entity Framework Power Tools (Beta 4)
Allow to design a code first model
Allow to reverse engineer an existing DB
Procudin...
Final Thoughts
Shall I use EF in real
business solutions?
You should consider it …
And make a decision based on
• Performances
• Scalability
• Time to market
• Shared knowledge
• T...
Don’t expect the very best performances you can ever achieve in your life
You have to pay the price for the infrastructure...
Grazie a tutti per la partecipazione
Riceverete il link per il download a slide e demo via email nei
prossimi giorni
Per c...
Upcoming SlideShare
Loading in...5
×

Be04 introduction to ef 6.0

58

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
58
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Be04 introduction to ef 6.0

  1. 1. Template designed by Introduction to EF 6.x Paolo Pialorsi paolo@pialorsi.com http://www.pialorsi.com/blog.aspx
  2. 2. brought to you by
  3. 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
  4. 4. Entity Framework 6 Let’s start
  5. 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. 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. 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)
  8. 8. Open Source! http://entityframework.codeplex.com/ • Source code • Nightly builds • Issue tracking • Feature specs • Design meeting notes Only EF team has commit rights Same license Same support Same quality What’s new in EF6 (2/4)
  9. 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. 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)
  11. 11. Usage scenarios Let’s play with Entity Framework 6
  12. 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. 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
  14. 14. Code First Migrations
  15. 15. Explicit configuration Data annotations Custom conventions Default conventions Order of Precedence
  16. 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
  17. 17. Code First Stored Procedures
  18. 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
  19. 19. Async Queries
  20. 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. 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
  22. 22. Connections and Transactions
  23. 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. 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
  25. 25. Code Based Configuration
  26. 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
  27. 27. Final Thoughts Shall I use EF in real business solutions?
  28. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×