SlideShare una empresa de Scribd logo
1 de 9
Entity
Framework
Optimization
By Rajeev Harbola
Design Consideration
 Avoid to put all the DB Objects into One Single Entity Model.
 Disable change tracking for entity if not needed.
NorthwindDataContext context = new NorthwindDataContext()
context.tblCities.MergeOption = MergeOption.NoTracking;
 Avoid fetching all the fields if not required
//Bad Practice
var customer = (from cust in dataContext.Customers select cust).ToList();
//Good Practice
var customer = (from cust in dataContext.Customers
select new {
customer. CustomerID,customer.Name,customer.Address}ToList ();
 Use Compiled Query wherever needed
Design Consideration
• Avoid using Contains
• Retrieve only required number of records.
Coding Guidelines
• Do Not Count After Query Execution
var empCount = db.Employees .Where(x => x.CreateDate <
DateTime.Now.AddDays(-10) .Count() //only executes a SQL COUNT
var emps = db.Employees .Where(x => x.CreateDate <
DateTime.Now.AddDays(-10)
var empCount = emps.Count() // returns all matching employees and
then executes a count
• Filter Before ToList()
//ToList() executed too early
var emps = db.Employees .Where(x => x.CreateDate <
DateTime.Now.AddDays(-10) .ToList() // All employees created within last 10 days queried
.Take(50) // List is filtered for the top 50
//ToList() executed last
var emps = db.Employees .Where(x => x.CreateDate <
DateTime.Now.AddDays(-10) .Take(50) .ToList() //Query made for top
50 employees created within last 10 days
Coding Guidelines
• Don’t Load Entities To Delete Them (very important)
var emp = db.Employees.Find(empID); //Executes a query against the database
db.Employees.Remove(emp);
db.SaveChanges(); //Executes a second hit to the database
var emp = new Employee { ID = empID }
db.Employees.Attach(emp);
db.Employees.Remove(emp);
db.SaveChanges(); //Executes a single hit to the database
• Use Eager Loading Instead of Lazy Loading
var employees = db.Employees; foreach(var emp in employees)
{
var address = emp.Address; //Database query is executed every time this line is hit
}
var employees = db.Employees .Include(x => x.Address) .ToList(); //All data loaded from
database
foreach(var emp in employees)
{
var address = emp.Address; //No database query executed
}
Coding Guidelines
• Query In-Memory Entities First
var emp = db.Employees.Find(empID); //Executes a query against the database
db.Employees.Remove(emp);
db.SaveChanges(); //Executes a second hit to the database
var emp = new Employee { ID = empID }
db.Employees.Attach(emp);
db.Employees.Remove(emp);
db.SaveChanges(); //Executes a single hit to the database
• Use Eager Loading Instead of Lazy Loading
var emp = db.Employees.Find(empID); // Queries in memory first
var emp = db.Employees.Where(x => x.ID == empID); //Always hits the database
var emp = db.Employees.Local.Where(x => x.ID == empID) ;
Advanced
• Use Compiled Query wherever needed
// create the entity object
NorthwindEntities mobjentity = new NorthwindEntities();
//Simple Query
IQueryable lstCus = from customer in mobjentity.tblCustomers where customer.City == "Delhi"
select customer;
//Compiled Query
Func> compiledQuery= CompiledQuery.Compile>((ctx, city) =>from customer in ctx.Customers
where customer.City == city
select customer);
• Debug and Optimize LINQ Query
IQueryable lstCus = from customer in mobjentity.tblCustomers
where customer.City == "Delhi"
select customer;
lstCus.Dump();
Last but not least
• Don’t Rely on Entity Framework Exclusively For Data
Access
• Finally, EF is great for productivity but executing raw SQL
or a stored procedure may often produce performance
benefits.
• In EF 4.0 and above the DbContext the SQLQuery()
method to execute raw SQL:
• var emps = db.Database.SQLQuery("select email from
Employees");Similarly use ExecuteSqlCommand() to
execute a stored procedure:
• var emps = db.Database.ExecuteSqlCommand("...");
THANKS
&
No question please

Más contenido relacionado

La actualidad más candente

Ransack ruby on rails - HuanND
Ransack ruby on rails - HuanNDRansack ruby on rails - HuanND
Ransack ruby on rails - HuanND
Framgia Vietnam
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
Aisha Mazhar
 
Cubes – ways of deployment
Cubes – ways of deploymentCubes – ways of deployment
Cubes – ways of deployment
Stefan Urbanek
 

La actualidad más candente (18)

Angular JS deep dive
Angular JS deep diveAngular JS deep dive
Angular JS deep dive
 
Tech Talk - JPA and Query Optimization - publish
Tech Talk  -  JPA and Query Optimization - publishTech Talk  -  JPA and Query Optimization - publish
Tech Talk - JPA and Query Optimization - publish
 
Database c# connetion
Database c# connetionDatabase c# connetion
Database c# connetion
 
Ruby on Rails Developer - Allerin
Ruby on Rails Developer - AllerinRuby on Rails Developer - Allerin
Ruby on Rails Developer - Allerin
 
Core Data Migration
Core Data MigrationCore Data Migration
Core Data Migration
 
Dev411
Dev411Dev411
Dev411
 
Ransack ruby on rails - HuanND
Ransack ruby on rails - HuanNDRansack ruby on rails - HuanND
Ransack ruby on rails - HuanND
 
Deadlock Prevention in Operating System
Deadlock Prevention in Operating SystemDeadlock Prevention in Operating System
Deadlock Prevention in Operating System
 
Experiment no 05
Experiment no 05Experiment no 05
Experiment no 05
 
Influxdb and time series data
Influxdb and time series dataInfluxdb and time series data
Influxdb and time series data
 
MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010MongoDB San Francisco DrupalCon 2010
MongoDB San Francisco DrupalCon 2010
 
Code craftsmanship saturdays second session
Code craftsmanship saturdays second sessionCode craftsmanship saturdays second session
Code craftsmanship saturdays second session
 
Przywitaj się z reactive extensions
Przywitaj się z reactive extensionsPrzywitaj się z reactive extensions
Przywitaj się z reactive extensions
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
 
Cubes – ways of deployment
Cubes – ways of deploymentCubes – ways of deployment
Cubes – ways of deployment
 
Spring batch showCase
Spring batch showCaseSpring batch showCase
Spring batch showCase
 
Introduce spark (by 조창원)
Introduce spark (by 조창원)Introduce spark (by 조창원)
Introduce spark (by 조창원)
 
Spring batch in action
Spring batch in actionSpring batch in action
Spring batch in action
 

Destacado

Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
Ramón Copa
 
Situação de Aprendizagem - LP - texto "Pausa"
Situação de Aprendizagem - LP - texto "Pausa"Situação de Aprendizagem - LP - texto "Pausa"
Situação de Aprendizagem - LP - texto "Pausa"
Lidiane Santos
 

Destacado (14)

live here 2015 US Open (tennis)
live here 2015 US Open (tennis)live here 2015 US Open (tennis)
live here 2015 US Open (tennis)
 
Salesforce couse in chennai
Salesforce couse in chennaiSalesforce couse in chennai
Salesforce couse in chennai
 
Propuestas de gestión del trabajo social
Propuestas de gestión del trabajo socialPropuestas de gestión del trabajo social
Propuestas de gestión del trabajo social
 
China Youthology's Whitepaper with Kiehl's: China Youth Attitude and Practice...
China Youthology's Whitepaper with Kiehl's: China Youth Attitude and Practice...China Youthology's Whitepaper with Kiehl's: China Youth Attitude and Practice...
China Youthology's Whitepaper with Kiehl's: China Youth Attitude and Practice...
 
2015/07/29 Eric Pan talk at Meiji Univ -Grow the difference -
2015/07/29 Eric Pan talk at Meiji Univ -Grow the difference -2015/07/29 Eric Pan talk at Meiji Univ -Grow the difference -
2015/07/29 Eric Pan talk at Meiji Univ -Grow the difference -
 
Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
Hispanoamerica- Estados Unidos quiere reconquistar su "patio trasero"- Sobera...
 
Desafuero parlamentario y acción penal privada
Desafuero parlamentario y acción penal privadaDesafuero parlamentario y acción penal privada
Desafuero parlamentario y acción penal privada
 
Energia electrica
Energia electricaEnergia electrica
Energia electrica
 
Situação de Aprendizagem - LP - texto "Pausa"
Situação de Aprendizagem - LP - texto "Pausa"Situação de Aprendizagem - LP - texto "Pausa"
Situação de Aprendizagem - LP - texto "Pausa"
 
live 2015 US Open (tennis) on mac
live 2015 US Open (tennis) on maclive 2015 US Open (tennis) on mac
live 2015 US Open (tennis) on mac
 
Blue Ocean Academy Training Infographic
Blue Ocean Academy Training InfographicBlue Ocean Academy Training Infographic
Blue Ocean Academy Training Infographic
 
certificate[1]
certificate[1]certificate[1]
certificate[1]
 
Broadcast 2015 US Open (tennis) live
Broadcast 2015 US Open (tennis) liveBroadcast 2015 US Open (tennis) live
Broadcast 2015 US Open (tennis) live
 
FPSB India- Resource Person Certificate
FPSB India- Resource Person CertificateFPSB India- Resource Person Certificate
FPSB India- Resource Person Certificate
 

Similar a Entity framework

Parallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр ПавлишакParallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр Павлишак
Igor Bronovskyy
 
Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUG
vraopolisetti
 
Dm adapter RubyConf.TW
Dm adapter RubyConf.TWDm adapter RubyConf.TW
Dm adapter RubyConf.TW
codingforrent
 

Similar a Entity framework (20)

Indexed db
Indexed dbIndexed db
Indexed db
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Parallel programming patterns (UA)
Parallel programming patterns (UA)Parallel programming patterns (UA)
Parallel programming patterns (UA)
 
Parallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр ПавлишакParallel programming patterns - Олександр Павлишак
Parallel programming patterns - Олександр Павлишак
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
 
Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUG
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
High Performance Core Data
High Performance Core DataHigh Performance Core Data
High Performance Core Data
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a database
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1Lazy vs. Eager Loading Strategies in JPA 2.1
Lazy vs. Eager Loading Strategies in JPA 2.1
 
Dm adapter RubyConf.TW
Dm adapter RubyConf.TWDm adapter RubyConf.TW
Dm adapter RubyConf.TW
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
Linq
LinqLinq
Linq
 
Core Data Migrations and A Better Option
Core Data Migrations and A Better OptionCore Data Migrations and A Better Option
Core Data Migrations and A Better Option
 

Último

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

Entity framework

  • 2. Design Consideration  Avoid to put all the DB Objects into One Single Entity Model.  Disable change tracking for entity if not needed. NorthwindDataContext context = new NorthwindDataContext() context.tblCities.MergeOption = MergeOption.NoTracking;  Avoid fetching all the fields if not required //Bad Practice var customer = (from cust in dataContext.Customers select cust).ToList(); //Good Practice var customer = (from cust in dataContext.Customers select new { customer. CustomerID,customer.Name,customer.Address}ToList ();  Use Compiled Query wherever needed
  • 3. Design Consideration • Avoid using Contains • Retrieve only required number of records.
  • 4. Coding Guidelines • Do Not Count After Query Execution var empCount = db.Employees .Where(x => x.CreateDate < DateTime.Now.AddDays(-10) .Count() //only executes a SQL COUNT var emps = db.Employees .Where(x => x.CreateDate < DateTime.Now.AddDays(-10) var empCount = emps.Count() // returns all matching employees and then executes a count • Filter Before ToList() //ToList() executed too early var emps = db.Employees .Where(x => x.CreateDate < DateTime.Now.AddDays(-10) .ToList() // All employees created within last 10 days queried .Take(50) // List is filtered for the top 50 //ToList() executed last var emps = db.Employees .Where(x => x.CreateDate < DateTime.Now.AddDays(-10) .Take(50) .ToList() //Query made for top 50 employees created within last 10 days
  • 5. Coding Guidelines • Don’t Load Entities To Delete Them (very important) var emp = db.Employees.Find(empID); //Executes a query against the database db.Employees.Remove(emp); db.SaveChanges(); //Executes a second hit to the database var emp = new Employee { ID = empID } db.Employees.Attach(emp); db.Employees.Remove(emp); db.SaveChanges(); //Executes a single hit to the database • Use Eager Loading Instead of Lazy Loading var employees = db.Employees; foreach(var emp in employees) { var address = emp.Address; //Database query is executed every time this line is hit } var employees = db.Employees .Include(x => x.Address) .ToList(); //All data loaded from database foreach(var emp in employees) { var address = emp.Address; //No database query executed }
  • 6. Coding Guidelines • Query In-Memory Entities First var emp = db.Employees.Find(empID); //Executes a query against the database db.Employees.Remove(emp); db.SaveChanges(); //Executes a second hit to the database var emp = new Employee { ID = empID } db.Employees.Attach(emp); db.Employees.Remove(emp); db.SaveChanges(); //Executes a single hit to the database • Use Eager Loading Instead of Lazy Loading var emp = db.Employees.Find(empID); // Queries in memory first var emp = db.Employees.Where(x => x.ID == empID); //Always hits the database var emp = db.Employees.Local.Where(x => x.ID == empID) ;
  • 7. Advanced • Use Compiled Query wherever needed // create the entity object NorthwindEntities mobjentity = new NorthwindEntities(); //Simple Query IQueryable lstCus = from customer in mobjentity.tblCustomers where customer.City == "Delhi" select customer; //Compiled Query Func> compiledQuery= CompiledQuery.Compile>((ctx, city) =>from customer in ctx.Customers where customer.City == city select customer); • Debug and Optimize LINQ Query IQueryable lstCus = from customer in mobjentity.tblCustomers where customer.City == "Delhi" select customer; lstCus.Dump();
  • 8. Last but not least • Don’t Rely on Entity Framework Exclusively For Data Access • Finally, EF is great for productivity but executing raw SQL or a stored procedure may often produce performance benefits. • In EF 4.0 and above the DbContext the SQLQuery() method to execute raw SQL: • var emps = db.Database.SQLQuery("select email from Employees");Similarly use ExecuteSqlCommand() to execute a stored procedure: • var emps = db.Database.ExecuteSqlCommand("...");