Richie Rump
Jorriss LLC
@Jorriss
www.jorriss.net
• What is Entity Framework?
• How does Entity Framework work?
• Why do developers like it?
• What should you, the DBA, be ...
Photo Credit: http://www.patrickfallonphoto.com/2008/11/04/election-2008-barack-obamas-election-night-grant-park/
Photo Credit: http://www.sacbee.com/static/weblogs/photos/2008/08/014666.html
Photo Credit: http://triggerpit.com/2010/11/22/incredible-pics-nasa-astronaut-wheelock/
Photo Credit: http://www.nydailynews.com/sports/football/giants/eli-manning-making-quarterback-article-1.1013353
Photo Credit: http://www.businessinsider.com/how-burger-king-went-from-mcdonalds-greatest-rival-to-total-train-wreck-2012-4
• Object Relational Mapping
• Converts pragmatic objects into a
relational database.
– Hibernate (Java)
– Active Record (R...
• ORM for .NET Applications
• Allows the developer to:
– Generate databases
– Save object data to a database
– Generate DD...
using (conn = new SqlConnection(connectString))
{
conn.Open();
DbCommand cmd = conn.CreateCommand();
cmd.Connection = conn...
var stores =
context.Stores.Include(c => c.Customers);
Lovingly stolen from Programming Entity Framework: Code First by Julie Lerman and Rowan Miller page 9.
Design Centric Code Centric
New
Database
Existing
Database
Model First
Create .edmx model in designer
Generate DB from .ed...
• v1.0 - .NET 3.5
• V4.0 - .NET 4.0. - Lazy Loading, POCO, Perf
Enhancements
• v4.2 – Bug Fixes - Semantic versioning
• v4...
• Developer works with objects.
• Focus on Business Domain (objects) not
DB, Connections, commands, etc.
• Developer Produ...
• Microsoft is making minimal investment
in ADO.Net.
• LINQ to SQL is essentially dead
• EF is now recommended for Data Ac...
• Database Generation
• N + 1 Problem
• Murder on the Index Express
• Searching
• Caching
• EF can generate databases
• EF Migrations can even generate
database updates and roll-forward or
rollback.
• I don’t rec...
• Things to look for in a ORM generated DB
– Normalization
– Relationships (They may not exist but should)
– Proper Types ...
• Occurs when object have a 1 : M
relationship.
Store Customer
• Use the Includes feature
• Use a Stored Procedure
• By default, the a LINQ query will return
ALL attributes in an object.
• Essentially, it’s performing a SELECT *
against ...
• Using the CONTAINS function in a LINQ
query creates a LIKE clause.
• LIKE has been know to decimate
performance.
• We ca...
• Complex LINQ queries can generate
some awful SQL.
• Cut your losses and replace the LINQ
query with a SQL one.
• This problem has been mostly fixed in EF
4.1+.
• But you can still run into problems with
Code First.
• Use a Caching Layer
– Redis
– ASP.Net has a caching library built in.
• Use a EF Profiler
– Hibernating Rhinos
– MiniPro...
• Julie Lerman’s Blog
http://thedatafarm.com/blog/
• Rowan Miller’s Blog
http://romiller.com
• Arthur Vicker’s Blog
http:/...
Richie Rump
@Jorriss
http://jorriss.net
http://slideshare.net/jorriss
http://dotnetmiami.com
Entity Framework For DBAs
Entity Framework For DBAs
Entity Framework For DBAs
Entity Framework For DBAs
Upcoming SlideShare
Loading in …5
×

Entity Framework For DBAs

1,588 views
1,387 views

Published on

Do you have applications in your environment that don't use SQL written by a person but by the application itself? No, the system isn't self-aware. Chances are the system is utilizing Microsoft's Entity Framework. Entity Framework (EF) and other object relational mapping technologies have been a boon for developers. But is Entity Framework a technology that developers should even be using? In this session, we'll review what Entity Framework is and how it's changed over time. We'll also dive into how Entity Framework works and what to look for when inspecting a database generated by Entity Framework. Finally, we'll review T-SQL generated by Entity Framework and give some tips on how to improve performance. If you're a data professional that manages databases that are accessed through Entity Framework or would like a basic knowledge of how Entity Framework works this session is for you.

Published in: Technology
4 Comments
1 Like
Statistics
Notes
  • Let me strongly suggest, don't use EF for any reason. Because we have lazy, unskilled developers, and persistently impatient people in upper management, we have entity framework. If you plan to scale, it will ultimately destroy your business. Your DBA's will alienate you as you turn the blame on them for your own ignorance. You cannot troubleshoot your code. You are forewarned. Why did it used to work but no longer works?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Slide 25 and 26 says use linq when you've hes already stated linq is dead and slide number 24 states use a stored procedure why not just use them to start with and have a well performing database
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Most of my 'horror' stories are focused around ORMs generating DBs. If you're looking for a high performing database don't let an ORM generate it for you. Look to a database architect.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Great presentation! Got any EF horror stories with solutions?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
1,588
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
8
Comments
4
Likes
1
Embeds 0
No embeds

No notes for slide

Entity Framework For DBAs

  1. 1. Richie Rump Jorriss LLC @Jorriss www.jorriss.net
  2. 2. • What is Entity Framework? • How does Entity Framework work? • Why do developers like it? • What should you, the DBA, be looking for in an Entity Framework project.
  3. 3. Photo Credit: http://www.patrickfallonphoto.com/2008/11/04/election-2008-barack-obamas-election-night-grant-park/
  4. 4. Photo Credit: http://www.sacbee.com/static/weblogs/photos/2008/08/014666.html
  5. 5. Photo Credit: http://triggerpit.com/2010/11/22/incredible-pics-nasa-astronaut-wheelock/
  6. 6. Photo Credit: http://www.nydailynews.com/sports/football/giants/eli-manning-making-quarterback-article-1.1013353
  7. 7. Photo Credit: http://www.businessinsider.com/how-burger-king-went-from-mcdonalds-greatest-rival-to-total-train-wreck-2012-4
  8. 8. • Object Relational Mapping • Converts pragmatic objects into a relational database. – Hibernate (Java) – Active Record (Ruby) Objects Mapping Data
  9. 9. • ORM for .NET Applications • Allows the developer to: – Generate databases – Save object data to a database – Generate DDL scripts from object changes – Generate SQL for data retrieval • All done with very minimal code.
  10. 10. using (conn = new SqlConnection(connectString)) { conn.Open(); DbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT Name, AccountNumber FROM sales.Store"; dbReader = cmd.ExecuteReader(); // do something cmd.Dispose(); conn.Close(); }
  11. 11. var stores = context.Stores.Include(c => c.Customers);
  12. 12. Lovingly stolen from Programming Entity Framework: Code First by Julie Lerman and Rowan Miller page 9.
  13. 13. Design Centric Code Centric New Database Existing Database Model First Create .edmx model in designer Generate DB from .edmx Classes auto-generate from .edmx Database First Reverse engineer .edmx model Classes auto-generate from .edmx Code First Define classes & mapping in code Database auto-created at runtime Code First Define classes & mapping in code Adapted from Programming Entity Framework: Code First by Julie Learman and Rowan Miller page 3.
  14. 14. • v1.0 - .NET 3.5 • V4.0 - .NET 4.0. - Lazy Loading, POCO, Perf Enhancements • v4.2 – Bug Fixes - Semantic versioning • v4.3 – Code First • V5.0 – .NET 4.5 - ENums, table-valued functions, Spatial Data Types • V6.0 – Async Support, Connection Resiliency
  15. 15. • Developer works with objects. • Focus on Business Domain (objects) not DB, Connections, commands, etc. • Developer Productivity • No need to write SQL or CRUD commands
  16. 16. • Microsoft is making minimal investment in ADO.Net. • LINQ to SQL is essentially dead • EF is now recommended for Data Access • EF is now open-source software
  17. 17. • Database Generation • N + 1 Problem • Murder on the Index Express • Searching • Caching
  18. 18. • EF can generate databases • EF Migrations can even generate database updates and roll-forward or rollback. • I don’t recommend blindly generating any database from any ORM. • DEMO
  19. 19. • Things to look for in a ORM generated DB – Normalization – Relationships (They may not exist but should) – Proper Types (NVarchar / BigInt are the exception) – Indexes on FKs – Primary Keys – Table Naming Convention (Singular vs. Plural) – Object Naming (such as Keys and Indexes)
  20. 20. • Occurs when object have a 1 : M relationship. Store Customer
  21. 21. • Use the Includes feature • Use a Stored Procedure
  22. 22. • By default, the a LINQ query will return ALL attributes in an object. • Essentially, it’s performing a SELECT * against the table. • Key lookup city. • To fix use LINQ projections.
  23. 23. • Using the CONTAINS function in a LINQ query creates a LIKE clause. • LIKE has been know to decimate performance. • We can fix this by using a Full Text Search
  24. 24. • Complex LINQ queries can generate some awful SQL. • Cut your losses and replace the LINQ query with a SQL one.
  25. 25. • This problem has been mostly fixed in EF 4.1+. • But you can still run into problems with Code First.
  26. 26. • Use a Caching Layer – Redis – ASP.Net has a caching library built in. • Use a EF Profiler – Hibernating Rhinos – MiniProfiler
  27. 27. • Julie Lerman’s Blog http://thedatafarm.com/blog/ • Rowan Miller’s Blog http://romiller.com • Arthur Vicker’s Blog http://blog.oneunicorn.com • #efhelp on twitter • StackOverflow (of course) • PluralSite – Julie Lerman’s EF videos
  28. 28. Richie Rump @Jorriss http://jorriss.net http://slideshare.net/jorriss http://dotnetmiami.com

×