06 | Integrating extra features and looking
forward
Christopher Harrison | Content Developer, Microsoft
Adam Tuliper | Technical Evangelist, Microsoft
Module Overview
• Stored procedures
• Increasing user experience with concurrency detection
• A few best practices
• Looking forward with Entity Framework 7
Stored procedures
Store procedures
• Why use stored procedures?
– Single point to secure – easier permissions
– Know exactly how DB is being queries
• Limits dynamic sql
– Still possible with sprocs, just more manual effort
• In general performance is _not_ a reason
– Virtually the same as sql query (pendulum swings both ways)
Stored procedures
• Support came in EF 6
– Only Fluent API based
• In the past could use procs manually
– var album = Database.SqlQuery<TriviaOption>("dbo.Proc….");
• Could map in the designer (which is going away)
• Code first will generate procedures for
– Insert, Delete, Update
• Wait – why no Select?
DEMODEMO
Integrating stored procedures
Increasing user experience with
concurrency detection
Concurrency
• As Christopher showed, easy to implement via concurrency token
– [TimeStamp]
– modelBuilder.Entity<YourEntity>()
.Property(e => e.Timestamp)
.IsRowVersion();
• Change detection can be enhanced via MVC Action Filters
• Let’s give the user the choice on how to proceed
DEMODEMO
Concurrency detection and user choice
A few best practices
Helpful hints in a web world
• Since the web layers (controller to view) are disconnected
– Always convert results to IEnumerable via .ToList()
• Ex. context.Albums.Where(o=>o.Title.Contains(search).ToList()
• Disable lazy loading in web environments
– context.Configuration.LazyLoadingEnabled = false;
– Use .Include to load related entities
– context.Albums.Include(o=>o.AlbumDetails)
• DbContext is not thread safe. Do not cache it!
– Always dispose DbContext when done
Context lifetime
• When context is gone, connection is gone
– Can’t (and shouldn’t) use connection from MVC view
– Get data, send to view
• Always execute result set when needed before exiting using()
using (var context = new MusicContext())
{
var albums = context.Albums
.Where(o=>o.Title.Contains(search))
.ToList());
return View(albums);
}
Watch out for…
• For complex joins, keep an eye on queries
– Remember context.Database.Log = s => Debug.WriteLine(s);
• Doing lots of inserts? AutoDetectChangesEnabled = false;
– EF detects changes on add to context and on save
– Can turn off and on again in same context lifetime
{
context.Configuration.AutoDetectChangesEnabled = false;
Do something
context.Configuration.AutoDetectChangesEnabled = true;
}
Async when appropriate
• EF supports async queries
– Async allows current thread to be used elsewhere
• Useful in case of network, db delays (long operations)
– Although not all the time, caution of overloading db
public async Task<ActionResult> Create(…)
{
if (ModelState.IsValid)
{
db.Albums.Add(album);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(album);
}
Consider Connection resiliency
• This is a connection retry policy
• Works great with async
• Four modes
– DefaultExecutionStrategy
– DefaultSqlExecutionStrategy
– DbExecutionStrategy
– SqlAzureExecutionStrategy
• throws RetryLimitExceededException
DEMODEMO
Connection Resiliency & Async
Looking forward with Entity Framework 7
Notable new features
• Designer has been removed – Code First Only
• Rewritten from ground up with performance in mind
• New platforms
– Linux, OSX, Mono, Windows Phone*, Windows Store*
• New data stores
• In memory database
• Update-Database now split
– Apply-Migration
– Script-Migration
Resources
• Additional patterns
– http://www.asp.net/mvc/overview/older-versions/getting-started-with-
ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-
patterns-in-an-asp-net-mvc-application
• Reducing Code First Database Chatter
– http://romiller.com/2014/06/10/reducing-code-first-database-chatter/
• EF7 Project home
– https://github.com/aspnet/EntityFramework
©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

PDF
C++ 11 Style : A Touch of Class
PPTX
04 managing the database
PPTX
01 introduction to entity framework
PDF
iOS development best practices
PDF
Building an Eclipse plugin to recommend changes to developers
ZIP
Promises in JavaScript with jQuery
PDF
Six simple steps to unit testing happiness
PPTX
Polyglot engineering
C++ 11 Style : A Touch of Class
04 managing the database
01 introduction to entity framework
iOS development best practices
Building an Eclipse plugin to recommend changes to developers
Promises in JavaScript with jQuery
Six simple steps to unit testing happiness
Polyglot engineering

What's hot (20)

PPTX
Oracle SQL Developer Top 10 Tips & Tricks
PPTX
PHP Frameworks, or how I learnt to stop worrying and love the code
PDF
PL/SQL Guilty Pleasures
PDF
AskTOM Office Hours - Dynamic SQL in PL/SQL
PDF
Test Driven Development in AEM/CQ5
PPTX
Take Full Advantage of the Oracle PL/SQL Compiler
PPTX
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
PPTX
Introducing domain driven design - dogfood con 2018
PDF
Unit Testing Oracle PL/SQL Code: utPLSQL, Excel and More
PDF
PDF
Using The Page Object Pattern
PPTX
Improving the Design of Existing Software
PPTX
Automated Acceptance Tests in .NET
PPTX
Software development fundamentals
PPTX
Improving the Quality of Existing Software
PDF
OLD APEX and PL/SQL
PPTX
Test Driven Development in CQ5/AEM
PPTX
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
PPTX
Most Useful Design Patterns
PPTX
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Oracle SQL Developer Top 10 Tips & Tricks
PHP Frameworks, or how I learnt to stop worrying and love the code
PL/SQL Guilty Pleasures
AskTOM Office Hours - Dynamic SQL in PL/SQL
Test Driven Development in AEM/CQ5
Take Full Advantage of the Oracle PL/SQL Compiler
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
Introducing domain driven design - dogfood con 2018
Unit Testing Oracle PL/SQL Code: utPLSQL, Excel and More
Using The Page Object Pattern
Improving the Design of Existing Software
Automated Acceptance Tests in .NET
Software development fundamentals
Improving the Quality of Existing Software
OLD APEX and PL/SQL
Test Driven Development in CQ5/AEM
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Most Useful Design Patterns
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Ad

Viewers also liked (20)

PPTX
05 managing transactions
PPTX
03 managing relationships
PPTX
01 introduction to entity framework
PPTX
02 beginning code first
PDF
000 introduction
PDF
001 hosting
PDF
презентация привязка модели и валидация данных
PDF
навигация и валидаторы презентация
PDF
05 cерверные элементы управления презентация
PPTX
Mva stf module 6 - rus
PPTX
Mva stf module 5 - rus
PPTX
Testing po
PPTX
Mva stf module 1 - rus
PPTX
Mva stf module 3 - rus
PPTX
Mva stf module 4 - rus
PPTX
Mva stf module 2 - rus
PPT
Getting started with angular js
PDF
jQuery for beginners
PPTX
Team Foundation Server Process Templates For Effective Project Management
05 managing transactions
03 managing relationships
01 introduction to entity framework
02 beginning code first
000 introduction
001 hosting
презентация привязка модели и валидация данных
навигация и валидаторы презентация
05 cерверные элементы управления презентация
Mva stf module 6 - rus
Mva stf module 5 - rus
Testing po
Mva stf module 1 - rus
Mva stf module 3 - rus
Mva stf module 4 - rus
Mva stf module 2 - rus
Getting started with angular js
jQuery for beginners
Team Foundation Server Process Templates For Effective Project Management
Ad

Similar to 06 integrating extra features and looking forward (20)

PDF
Getting Started with Sql Server Compact Edition
PDF
Getting Started with SQL Server Compact Edition 3.51
PDF
Alfresco Business Reporting - Tech Talk Live 20130501
PDF
01 overview-and-setup
PDF
Codeigniter
PPTX
Spring data jpa are used to develop spring applications
PPT
Sql interview-question-part-9
PPT
Sql interview question part 9
PPT
Ebook9
PPT
Ebook9
PPTX
Twelve Factor - Designing for Change
PPTX
Integration-Monday-Terraform-Serverless
PPTX
Oracle Database Cloud Service
PDF
KYSUC - Keep Your Schema Under Control
PPTX
Dev Ops for systems of record - Talk at Agile Australia 2015
PDF
Introduction to CakePHP
PDF
Introduction to CakePHP
KEY
Standardizing and Managing Your Infrastructure - MOSC 2011
PDF
01 demystifying mysq-lfororacledbaanddeveloperv1
PPTX
Impact of cloud services on the work of oracle technology experts
Getting Started with Sql Server Compact Edition
Getting Started with SQL Server Compact Edition 3.51
Alfresco Business Reporting - Tech Talk Live 20130501
01 overview-and-setup
Codeigniter
Spring data jpa are used to develop spring applications
Sql interview-question-part-9
Sql interview question part 9
Ebook9
Ebook9
Twelve Factor - Designing for Change
Integration-Monday-Terraform-Serverless
Oracle Database Cloud Service
KYSUC - Keep Your Schema Under Control
Dev Ops for systems of record - Talk at Agile Australia 2015
Introduction to CakePHP
Introduction to CakePHP
Standardizing and Managing Your Infrastructure - MOSC 2011
01 demystifying mysq-lfororacledbaanddeveloperv1
Impact of cloud services on the work of oracle technology experts

Recently uploaded (20)

PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
HVAC Specification 2024 according to central public works department
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
International_Financial_Reporting_Standa.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
IGGE1 Understanding the Self1234567891011
A powerpoint presentation on the Revised K-10 Science Shaping Paper
FORM 1 BIOLOGY MIND MAPS and their schemes
TNA_Presentation-1-Final(SAVE)) (1).pptx
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
AI-driven educational solutions for real-life interventions in the Philippine...
Uderstanding digital marketing and marketing stratergie for engaging the digi...
My India Quiz Book_20210205121199924.pdf
Empowerment Technology for Senior High School Guide
HVAC Specification 2024 according to central public works department
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Introduction to pro and eukaryotes and differences.pptx
History, Philosophy and sociology of education (1).pptx
International_Financial_Reporting_Standa.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
IGGE1 Understanding the Self1234567891011

06 integrating extra features and looking forward

  • 1. 06 | Integrating extra features and looking forward Christopher Harrison | Content Developer, Microsoft Adam Tuliper | Technical Evangelist, Microsoft
  • 2. Module Overview • Stored procedures • Increasing user experience with concurrency detection • A few best practices • Looking forward with Entity Framework 7
  • 4. Store procedures • Why use stored procedures? – Single point to secure – easier permissions – Know exactly how DB is being queries • Limits dynamic sql – Still possible with sprocs, just more manual effort • In general performance is _not_ a reason – Virtually the same as sql query (pendulum swings both ways)
  • 5. Stored procedures • Support came in EF 6 – Only Fluent API based • In the past could use procs manually – var album = Database.SqlQuery<TriviaOption>("dbo.Proc…."); • Could map in the designer (which is going away) • Code first will generate procedures for – Insert, Delete, Update • Wait – why no Select?
  • 7. Increasing user experience with concurrency detection
  • 8. Concurrency • As Christopher showed, easy to implement via concurrency token – [TimeStamp] – modelBuilder.Entity<YourEntity>() .Property(e => e.Timestamp) .IsRowVersion(); • Change detection can be enhanced via MVC Action Filters • Let’s give the user the choice on how to proceed
  • 10. A few best practices
  • 11. Helpful hints in a web world • Since the web layers (controller to view) are disconnected – Always convert results to IEnumerable via .ToList() • Ex. context.Albums.Where(o=>o.Title.Contains(search).ToList() • Disable lazy loading in web environments – context.Configuration.LazyLoadingEnabled = false; – Use .Include to load related entities – context.Albums.Include(o=>o.AlbumDetails) • DbContext is not thread safe. Do not cache it! – Always dispose DbContext when done
  • 12. Context lifetime • When context is gone, connection is gone – Can’t (and shouldn’t) use connection from MVC view – Get data, send to view • Always execute result set when needed before exiting using() using (var context = new MusicContext()) { var albums = context.Albums .Where(o=>o.Title.Contains(search)) .ToList()); return View(albums); }
  • 13. Watch out for… • For complex joins, keep an eye on queries – Remember context.Database.Log = s => Debug.WriteLine(s); • Doing lots of inserts? AutoDetectChangesEnabled = false; – EF detects changes on add to context and on save – Can turn off and on again in same context lifetime { context.Configuration.AutoDetectChangesEnabled = false; Do something context.Configuration.AutoDetectChangesEnabled = true; }
  • 14. Async when appropriate • EF supports async queries – Async allows current thread to be used elsewhere • Useful in case of network, db delays (long operations) – Although not all the time, caution of overloading db public async Task<ActionResult> Create(…) { if (ModelState.IsValid) { db.Albums.Add(album); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(album); }
  • 15. Consider Connection resiliency • This is a connection retry policy • Works great with async • Four modes – DefaultExecutionStrategy – DefaultSqlExecutionStrategy – DbExecutionStrategy – SqlAzureExecutionStrategy • throws RetryLimitExceededException
  • 17. Looking forward with Entity Framework 7
  • 18. Notable new features • Designer has been removed – Code First Only • Rewritten from ground up with performance in mind • New platforms – Linux, OSX, Mono, Windows Phone*, Windows Store* • New data stores • In memory database • Update-Database now split – Apply-Migration – Script-Migration
  • 19. Resources • Additional patterns – http://www.asp.net/mvc/overview/older-versions/getting-started-with- ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work- patterns-in-an-asp-net-mvc-application • Reducing Code First Database Chatter – http://romiller.com/2014/06/10/reducing-code-first-database-chatter/ • EF7 Project home – https://github.com/aspnet/EntityFramework
  • 20. ©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. ©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Editor's Notes

  • #2: 1
  • #7: modelBuilder    .Entity<Album>()    .MapToStoredProcedures(); modelBuilder     .Entity<Album>()     .MapToStoredProcedures(s =>       s.Update(u => u.HasName(“Blog_"))        .Delete(d => d.HasName("delete_blog"))        .Insert(i => i.HasName("insert_blog"))); modelBuilder.Entity<TriviaOption>().MapToStoredProcedures(p => p.Insert(proc => proc.HasName("Proc_AddAlbum") .Result(r => r.Id,"id")));
  • #15: ToListAsync await db.SaveChangesAsync public async Task<ActionResult> Return task [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album) { if (ModelState.IsValid) { db.Albums.Add(album); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(album); }
  • #16: https://code.msdn.microsoft.com/ASPNET-MVC-Application-b01a9fe8
  • #17: Change method to be async for save