Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Entity Data Model

877 views

Published on

Learn how to create and use an Entity Data Model, explore the raw XML behind the model as a way to understand how Entity Framework works, and see how to use stored procedures within an Entity Framework model.

Published in: Technology
  • Be the first to comment

The Entity Data Model

  1. 1. The Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  2. 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  3. 3. Objectives• Learn how to create and use an Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  4. 4. Objectives• Learn how to create and use an Entity Data Model• Explore the raw XML behind the model as a way to understand how Entity Framework works Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  5. 5. Objectives• Learn how to create and use an Entity Data Model• Explore the raw XML behind the model as a way to understand how Entity Framework works• See how to use stored procedures within an Entity Framework model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  6. 6. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  7. 7. Agenda• Introduction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  8. 8. Agenda• Introduction• Creating and Using an Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  9. 9. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  10. 10. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw• Using Stored Procedures in the Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  11. 11. Introduction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  12. 12. Introduction• Key link between entity objects and data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  13. 13. Introduction• Key link between entity objects and data  Conceptual model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  14. 14. Introduction• Key link between entity objects and data  Conceptual model  Storage model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  15. 15. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  16. 16. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model• Application design is often at odds with database design Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  17. 17. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model• Application design is often at odds with database design• Can work with model in designer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  18. 18. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model• Application design is often at odds with database design• Can work with model in designer  Or get messy with the XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  19. 19. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model• Application design is often at odds with database design• Can work with model in designer  Or get messy with the XML• At build, split into three XML files Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  20. 20. Introduction• Key link between entity objects and data  Conceptual model  Storage model  Mapping model• Application design is often at odds with database design• Can work with model in designer  Or get messy with the XML• At build, split into three XML files• Developers don’t have to know the database Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  21. 21. The Models within the Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  22. 22. The Models within the Model• Conceptual Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  23. 23. The Models within the Model• Conceptual Model  The actual Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  24. 24. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  25. 25. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  26. 26. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  27. 27. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas  Can be similar to conceptual model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  28. 28. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas  Can be similar to conceptual model  Decupling of conceptual design from the database Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  29. 29. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas  Can be similar to conceptual model  Decupling of conceptual design from the database• Mapping Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  30. 30. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas  Can be similar to conceptual model  Decupling of conceptual design from the database• Mapping Model  Bridge between conceptual and storage models Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  31. 31. The Models within the Model• Conceptual Model  The actual Entity Data Model  Provides what is needed to create data objects• Storage Model  Represents the database schemas  Can be similar to conceptual model  Decupling of conceptual design from the database• Mapping Model  Bridge between conceptual and storage models  Map object properties to database fields Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  32. 32. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  33. 33. Agenda• Introduction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  34. 34. Agenda• Introduction• Creating and Using an Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  35. 35. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  36. 36. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw• Using Stored Procedures in the Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  37. 37. Creating and Using an Entity DataModel Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  38. 38. Creating and Using an Entity DataModel• Can create from scratch using XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  39. 39. Creating and Using an Entity DataModel• Can create from scratch using XML  More productive using the designer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  40. 40. Creating and Using an Entity DataModel• Can create from scratch using XML  More productive using the designer• Three approaches Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  41. 41. Creating and Using an Entity DataModel• Can create from scratch using XML  More productive using the designer• Three approaches  Database-first Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  42. 42. Creating and Using an Entity DataModel• Can create from scratch using XML  More productive using the designer• Three approaches  Database-first  Model-first Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  43. 43. Creating and Using an Entity DataModel• Can create from scratch using XML  More productive using the designer• Three approaches  Database-first  Model-first  Code-first Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  44. 44. Creating a Model Using Database-First Design Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  45. 45. Creating a Model Using Database-First Design• Directly supported by the Entity Framework template Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  46. 46. Creating a Model Using Database-First Design• Directly supported by the Entity Framework template• Wizard lets you Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  47. 47. Creating a Model Using Database-First Design• Directly supported by the Entity Framework template• Wizard lets you  Reverse-engineer the database schma Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  48. 48. Creating a Model Using Database-First Design• Directly supported by the Entity Framework template• Wizard lets you  Reverse-engineer the database schma  Select tables, views, and stored procedures to include Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  49. 49. Creating a Model Using Database-First Design• Directly supported by the Entity Framework template• Wizard lets you  Reverse-engineer the database schma  Select tables, views, and stored procedures to include  Build the model from selected objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  50. 50. Multiplicity Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  51. 51. Multiplicity• Used with associations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  52. 52. Multiplicity• Used with associations• Number of entities that can be on each end of an association Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  53. 53. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  54. 54. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  55. 55. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  56. 56. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  57. 57. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1  Many: * Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  58. 58. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1  Many: *• Can combine in various ways, such as Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  59. 59. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1  Many: *• Can combine in various ways, such as  1:* Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  60. 60. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1  Many: *• Can combine in various ways, such as  1:*  0..1:* Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  61. 61. Multiplicity• Used with associations• Number of entities that can be on each end of an association  Sometimes referred to as cardinality• Three options  One: 1  Zero or one: 0..1  Many: *• Can combine in various ways, such as  1:*  0..1:*  *:* Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  62. 62. Entity Data Model Object Properties Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  63. 63. Entity Data Model Object Properties• Typical for Visual Studio Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  64. 64. Entity Data Model Object Properties• Typical for Visual Studio• Use Properties windows to set values of properties for various objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  65. 65. Entity Data Model Object Properties• Typical for Visual Studio• Use Properties windows to set values of properties for various objects• Model stores some in model’s XML to define a model, others guide object creation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  66. 66. Creating a Model UsingModel-First Design Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  67. 67. Creating a Model UsingModel-First Design• Database-first design is common Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  68. 68. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  69. 69. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application  Could create the database first Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  70. 70. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application  Could create the database first  But model-first is another option Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  71. 71. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application  Could create the database first  But model-first is another option  Strictly speaking, Entity Framework has always had this option Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  72. 72. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application  Could create the database first  But model-first is another option  Strictly speaking, Entity Framework has always had this option• Generate Database from Model option Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  73. 73. Creating a Model UsingModel-First Design• Database-first design is common• Sometimes creating a new database with the application  Could create the database first  But model-first is another option  Strictly speaking, Entity Framework has always had this option• Generate Database from Model option• Entity Designer Database Generation Power Pack Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  74. 74. Sled Dog Event Registration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  75. 75. Sled Dog Event Registration Team Event Race FirstName Name 1 * 1 * Distance LastName EventDate DogCount City Sponsor Trail Country Location DogCount Mushing Skijoring Leader1 Dog1 Leader2 Dog2 Dog3 NumberOfLeaders Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  76. 76. Explore the Model with theModel Browser Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  77. 77. Explore the Model with theModel Browser• Working with large models can be hard in the designer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  78. 78. Explore the Model with theModel Browser• Working with large models can be hard in the designer  Can be hard to understand the structure of the model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  79. 79. Explore the Model with theModel Browser• Working with large models can be hard in the designer  Can be hard to understand the structure of the model  Mapping Details windows doesn’t have details of storage model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  80. 80. Explore the Model with theModel Browser• Working with large models can be hard in the designer  Can be hard to understand the structure of the model  Mapping Details windows doesn’t have details of storage model• Overcome these limitations with the Model Browser Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  81. 81. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  82. 82. Agenda• Introduction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  83. 83. Agenda• Introduction• Creating and Using an Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  84. 84. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  85. 85. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw• Using Stored Procedures in the Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  86. 86. Entity Data Model in the Raw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  87. 87. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  88. 88. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  89. 89. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  90. 90. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML• Need to have a basic understanding of the XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  91. 91. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML• Need to have a basic understanding of the XML  Sometimes have to manipulate the XML directly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  92. 92. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML• Need to have a basic understanding of the XML  Sometimes have to manipulate the XML directly• Can use any text editor Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  93. 93. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML• Need to have a basic understanding of the XML  Sometimes have to manipulate the XML directly• Can use any text editor  But Visual Studio XML editor provides color-coding, well- formedness checks, and Intellisense Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  94. 94. Entity Data Model in the Raw• Designer is a graphical view only of the conceptual model  Exposes most, but not all, features  Ultimately, just a pretty face on the XML• Need to have a basic understanding of the XML  Sometimes have to manipulate the XML directly• Can use any text editor  But Visual Studio XML editor provides color-coding, well- formedness checks, and Intellisense• Can’t have open in designer and XML simultaneously Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  95. 95. XML Definition Languages Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  96. 96. XML Definition Languages• One for each model: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  97. 97. XML Definition Languages• One for each model:  Conceptual model uses Conceptual Schema Definition Language (CSDL) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  98. 98. XML Definition Languages• One for each model:  Conceptual model uses Conceptual Schema Definition Language (CSDL)  Storage model uses Store Schema Definition Language (SSDL) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  99. 99. XML Definition Languages• One for each model:  Conceptual model uses Conceptual Schema Definition Language (CSDL)  Storage model uses Store Schema Definition Language (SSDL)  Mapping model uses Mapping Specification Language (MSL) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  100. 100. XML Definition Languages• One for each model:  Conceptual model uses Conceptual Schema Definition Language (CSDL)  Storage model uses Store Schema Definition Language (SSDL)  Mapping model uses Mapping Specification Language (MSL)• Visual Studio includes XML schema files Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  101. 101. Model Build Mechanics Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  102. 102. Model Build Mechanics• .edmx file contains XML for all three models Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  103. 103. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  104. 104. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  105. 105. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  106. 106. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file  Storage model to .ssdl file Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  107. 107. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file  Storage model to .ssdl file  Mapping model to .msl file Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  108. 108. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file  Storage model to .ssdl file  Mapping model to .msl file• By default, stored in project assembly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  109. 109. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file  Storage model to .ssdl file  Mapping model to .msl file• By default, stored in project assembly  Can output three physical files Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  110. 110. Model Build Mechanics• .edmx file contains XML for all three models  Plus support for the graphical designer• Saves as three files at build:  Conceptual model to .csdl file  Storage model to .ssdl file  Mapping model to .msl file• By default, stored in project assembly  Can output three physical files  Change the MetadataArtifactProcessing property of the entity container Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  111. 111. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  112. 112. Agenda• Introduction Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  113. 113. Agenda• Introduction• Creating and Using an Entity Data Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  114. 114. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  115. 115. Agenda• Introduction• Creating and Using an Entity Data Model• Entity Data Model in the Raw• Using Stored Procedures in the Model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  116. 116. Using Stored Procedures in theModel Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  117. 117. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  118. 118. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  119. 119. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  120. 120. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  121. 121. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job• Stored procedures vs. dynamic code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  122. 122. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job• Stored procedures vs. dynamic code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  123. 123. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job• Stored procedures vs. dynamic code  Pick one or the other and go for it Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  124. 124. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job• Stored procedures vs. dynamic code  Pick one or the other and go for it• Entity Framework does both well Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  125. 125. Using Stored Procedures in theModel• Entity Framework can automatically generate all code needed to do CRUD• Not necessarily ideal from DBA’s perspective  Job is to make sure data is secure, performs well, is scalable, and meets needs of the application  Dynamic SQL complicates the job• Stored procedures vs. dynamic code  Pick one or the other and go for it• Entity Framework does both well  Current version generates good code, mostly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  126. 126. Ways to Use Stored Procedures Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  127. 127. Ways to Use Stored Procedures• Few different ways Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  128. 128. Ways to Use Stored Procedures• Few different ways  Replace an entity’s insert, update, and delete functions to use stored procedures Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  129. 129. Ways to Use Stored Procedures• Few different ways  Replace an entity’s insert, update, and delete functions to use stored procedures  Use stored procedures that return data to entities are scalar values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  130. 130. Ways to Use Stored Procedures• Few different ways  Replace an entity’s insert, update, and delete functions to use stored procedures  Use stored procedures that return data to entities are scalar values• Entity Framework uses terms stored procedure and function interchangeably Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  131. 131. Updating the Model from theDatabase Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  132. 132. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  133. 133. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  134. 134. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  135. 135. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database• Will use several stored procedures Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  136. 136. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database• Will use several stored procedures  InsertCustomer, UpdateCustomer, and DeleteCustomer Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  137. 137. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database• Will use several stored procedures  InsertCustomer, UpdateCustomer, and DeleteCustomer  GetCustomersByRegion Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  138. 138. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database• Will use several stored procedures  InsertCustomer, UpdateCustomer, and DeleteCustomer  GetCustomersByRegion  GetProductListByCategory Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  139. 139. Updating the Model from theDatabase• Have to include stored procedures in the model before you can use them  Only imported tables and views• Entity Framework supports updating the model from the database• Will use several stored procedures  InsertCustomer, UpdateCustomer, and DeleteCustomer  GetCustomersByRegion  GetProductListByCategory  GetProductCategoryAveragePrice Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  140. 140. Using Stored Procedures toChange an Entity Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  141. 141. Using Stored Procedures toChange an Entity• One of the most common ways to use stored procedures Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  142. 142. Using Stored Procedures toChange an Entity• One of the most common ways to use stored procedures• Replaces Entity Framework default behavior for an entity Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  143. 143. Using Stored Procedures toChange an Entity• One of the most common ways to use stored procedures• Replaces Entity Framework default behavior for an entity• Will use the Customer object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  144. 144. Using Stored Procedures thatRead Data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  145. 145. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  146. 146. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  147. 147. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  148. 148. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data• GetCustomersByRegion returns all of the fields of the Customer table Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  149. 149. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data• GetCustomersByRegion returns all of the fields of the Customer table• GetProductListByCategory returns fields from the Product and ProductCategory tables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  150. 150. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data• GetCustomersByRegion returns all of the fields of the Customer table• GetProductListByCategory returns fields from the Product and ProductCategory tables• Complex type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  151. 151. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data• GetCustomersByRegion returns all of the fields of the Customer table• GetProductListByCategory returns fields from the Product and ProductCategory tables• Complex type  Neither an entity or scalar type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  152. 152. Using Stored Procedures thatRead Data• Use stored procedures that read data in the model  Materialize an entity object  Random sets of data• GetCustomersByRegion returns all of the fields of the Customer table• GetProductListByCategory returns fields from the Product and ProductCategory tables• Complex type  Neither an entity or scalar type  Use Model Browser to work with Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  153. 153. Using Stored Procedures thatReturn a Scalar Value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  154. 154. Using Stored Procedures thatReturn a Scalar Value• Another option is to retrieve a scalar value from a stored procedure Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  155. 155. Using Stored Procedures thatReturn a Scalar Value• Another option is to retrieve a scalar value from a stored procedure• Dirty little secret Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  156. 156. Using Stored Procedures thatReturn a Scalar Value• Another option is to retrieve a scalar value from a stored procedure• Dirty little secret  Stored procedure still returns a result set Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  157. 157. Using Stored Procedures thatReturn a Scalar Value• Another option is to retrieve a scalar value from a stored procedure• Dirty little secret  Stored procedure still returns a result set  Entity Framework extracts the value, sort of Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  158. 158. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  159. 159. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  160. 160. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  161. 161. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!• Learn more about Entity Framework on SlideShare: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  162. 162. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!• Learn more about Entity Framework on SlideShare:  Introducing the Entity Framework Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

×