{"id":122,"date":"2018-03-26T00:56:00","date_gmt":"2018-03-25T22:56:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/03\/26\/restful-web-services-tutorial-6-how-to-create-an-entity-framework-class-diagram-in-visual-studio\/"},"modified":"2020-11-05T14:14:29","modified_gmt":"2020-11-05T13:14:29","slug":"restful-web-services-tutorial-6-how-to-create-an-entity-framework-class-diagram-in-visual-studio","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-6-how-to-create-an-entity-framework-class-diagram-in-visual-studio\/","title":{"rendered":"RESTful Web Services Tutorial 6 &#8211; How to Create an Entity Framework Class Diagram in Visual Studio"},"content":{"rendered":"<p>In this tutorial, I will teach you how to generate your class diagram in Visual Studio. This is very interesting because I normally use Microsoft Visio or some other designer to manually draw class diagrams in the past. And the more interesting thing is that this diagram is in sync with your database design.<\/p>\n<p>&nbsp;<\/p>\n<p>To generate the class diagram in Visual Studio, follow the steps below:<\/p>\n<p><b>Step 1<\/b>: Open Visual Studio<br \/>\n<b>Step 2:<\/b> Open the Solution we created in the previous tutorial. You can create a new Solution if you did not follow the previous tutorial.<br \/>\n<b>Step 3:<\/b> In the Solution Explorer, right-click on your project and select Add &gt; New Item to open the New Item dialog.<\/p>\n<p>Under Visual C#, select Data as shown in Figure 1<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-PlAsyLD5V1o\/WrgwKxV0IBI\/AAAAAAAABkQ\/CfmZa2emq8IkU0nqCBNPKbtTUzXgzX8QQCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B1%2B-%2BAdd%2Bnew%2Bitem.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-PlAsyLD5V1o\/WrgwKxV0IBI\/AAAAAAAABkQ\/CfmZa2emq8IkU0nqCBNPKbtTUzXgzX8QQCLcBGAs\/s640\/Tutorial%2B6%2BFigure%2B1%2B-%2BAdd%2Bnew%2Bitem.jpg\" width=\"640\" height=\"404\" border=\"0\" data-original-height=\"650\" data-original-width=\"1025\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 1<\/b>: New EF Data Model<\/div>\n<div><\/div>\n<p><b>Step 4:<\/b> In the list of items, select ADO.NET Entity Data Model<br \/>\n<b>Step 5<\/b>: Give it a name like EmployeeDataModel.<br \/>\n<b>Step 6: <\/b>Click Add to display the Entity Data Model wizard as shown in Figure 2<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-3zyzmDJZaS0\/Wrgxm_iN_pI\/AAAAAAAABkc\/XZCG_4gU8GEn-dEnvu1OgAqav_mykOFLACLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B2%2B-%2BEntity%2BData%2BModel%2BWizard.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-3zyzmDJZaS0\/Wrgxm_iN_pI\/AAAAAAAABkc\/XZCG_4gU8GEn-dEnvu1OgAqav_mykOFLACLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B2%2B-%2BEntity%2BData%2BModel%2BWizard.jpg\" width=\"400\" height=\"365\" border=\"0\" data-original-height=\"551\" data-original-width=\"602\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\">\u00a0<b>Figure 2:<\/b> Entity Data Model Wizard<\/div>\n<div><\/div>\n<p><b>Step 7: <\/b>Make sure that <span style=\"color: blue;\">&#8216;EF Designer from database<\/span>&#8216; is selected<br \/>\n<b>Step 8: <\/b>Click on Next. The next Wizard Step is displayed as shown in Figure 3<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-G-YYCsTJsQ4\/Wrg05YuiFnI\/AAAAAAAABko\/X8IC5kz9bDwf__HCCrf2Ku6Xge-QajJYwCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B3.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-G-YYCsTJsQ4\/Wrg05YuiFnI\/AAAAAAAABko\/X8IC5kz9bDwf__HCCrf2Ku6Xge-QajJYwCLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B3.jpg\" width=\"400\" height=\"365\" border=\"0\" data-original-height=\"551\" data-original-width=\"602\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 3:<\/b> Choosing Database Connection<\/div>\n<p><ins style=\"display: block; text-align: center;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\"><\/ins><br \/>\n<b>Define Database Connection Parameters<\/b><br \/>\nNow we need to connect to the database we created by specifying the name of the server, the instance and the name of the database.<\/p>\n<p><b>Step 9: <\/b>Click on <span style=\"color: blue;\">New Connection<\/span> to display the Connection Properties dialog<\/p>\n<p>In the Connection Properties dialog box that appears, enter the Connection Properties as shown in Figure 4<br \/>\n<b>Step 10: <\/b>Enter the Server Name<br \/>\n<b>Step 11: <\/b>Select the name of the database you created under <span style=\"color: blue;\">Select or enter database name <\/span><\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-obI9EnQzD9g\/Wrg1AzQyQOI\/AAAAAAAABks\/Kei4O-RWpAwN-eQ8hLvS7WaX3xqIwlrrwCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B4.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-obI9EnQzD9g\/Wrg1AzQyQOI\/AAAAAAAABks\/Kei4O-RWpAwN-eQ8hLvS7WaX3xqIwlrrwCLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B4.jpg\" width=\"268\" height=\"400\" border=\"0\" data-original-height=\"567\" data-original-width=\"382\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 4: <\/b>Database Connection Parameter<\/div>\n<div><\/div>\n<p>You could also Click on Test Connection to ensure that the connection succeeds.<\/p>\n<p><b>Step 12: <\/b>Click on Ok to get back to the Data Model Wizard. A dialog box appears prompting you to select an Entity Framework.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-zxwMf0g5jw8\/Wrg1Pk5vycI\/AAAAAAAABkw\/yQKfGjkpFXQB9PPiG3VQk0D8t_2oNNz6wCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B5.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-zxwMf0g5jw8\/Wrg1Pk5vycI\/AAAAAAAABkw\/yQKfGjkpFXQB9PPiG3VQk0D8t_2oNNz6wCLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B5.jpg\" width=\"400\" height=\"361\" border=\"0\" data-original-height=\"488\" data-original-width=\"539\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 5:<\/b> Connnection Settings (ConnectionString)<\/div>\n<div><\/div>\n<div><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-537E2CXW2kU\/Wrg1Y3QFooI\/AAAAAAAABk4\/F6aeGxnsSZQFwR2xKh2xU59jBk1lXcgxwCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B6.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-537E2CXW2kU\/Wrg1Y3QFooI\/AAAAAAAABk4\/F6aeGxnsSZQFwR2xKh2xU59jBk1lXcgxwCLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B6.jpg\" width=\"400\" height=\"361\" border=\"0\" data-original-height=\"488\" data-original-width=\"539\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 6:<\/b> Choose Entity Framework Version<\/div>\n<div><\/div>\n<p><b>Step 13: <\/b>Select Entity Framework 6.0. Other versions would also work<\/p>\n<p><b>Step 14: <\/b>Click on Next<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/1.bp.blogspot.com\/-SIgxm4f5IMU\/Wrg2SebQwpI\/AAAAAAAABlM\/gh4dCTxZcpcsFlHAikgIzwSfDF5bNjNkwCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B7.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/1.bp.blogspot.com\/-SIgxm4f5IMU\/Wrg2SebQwpI\/AAAAAAAABlM\/gh4dCTxZcpcsFlHAikgIzwSfDF5bNjNkwCLcBGAs\/s400\/Tutorial%2B6%2BFigure%2B7.jpg\" width=\"400\" height=\"361\" border=\"0\" data-original-height=\"488\" data-original-width=\"539\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 7: <\/b>Choose Database object(Tables)<\/div>\n<p>&nbsp;<\/p>\n<p><b>Step 15: <\/b>Select the checkbox for Tables (We discuss Views and Stored Procedures in subsequent lessons)<br \/>\n<b>Step 16: <\/b>Click Finish to complete the task<\/p>\n<p>After a few seconds, the Class diagram is generated as you can see in Figure 8. Isn&#8217;t this amazing!<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-l-DU4qUMUVI\/Wrg3pGHpoBI\/AAAAAAAABlg\/J6Q_Udl0lx4h3PLyb4UNEa0fEwvozxOLgCLcBGAs\/s1600\/Tutorial%2B6%2BFigure%2B8.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-l-DU4qUMUVI\/Wrg3pGHpoBI\/AAAAAAAABlg\/J6Q_Udl0lx4h3PLyb4UNEa0fEwvozxOLgCLcBGAs\/s640\/Tutorial%2B6%2BFigure%2B8.jpg\" width=\"640\" height=\"370\" border=\"0\" data-original-height=\"795\" data-original-width=\"1369\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><b>Figure 8: <\/b>Completed Class Diagram<\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><b>Notes About This Class Diagram<\/b><br \/>\nNotice that there is a fifth object in the diagram with a name of sysdiagram. Delete it.<br \/>\nYou can also see that this diagram resembles the relationship diagram we created in <a href=\"https:\/\/kindsonthegenius.com\/blog\/restful-web-services-tutorial-5-create-employee-database-in-ms-sql-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tutorial 5<\/a>, with the relationships labelled.<\/p>\n<p>Each of the classes is has two sections<\/p>\n<ul>\n<li><span style=\"color: #274e13;\"><i>Properties:<\/i><\/span> This corresponds to the fields of the particular table in the dabase<\/li>\n<li><i><span style=\"color: #274e13;\">Navigation Properties:<\/span><\/i> This is additional information that could be selected along with the given record. For instance, for an Employee, we need to select his address, country and department. Note that they have singular name. In other tables like Departments, the navigation properties specifies the Employees that belong to a particular department. Also note that the navigation property here is plural reflecting the one-to-many relationship(one department to many employees). This would become clearer as we progress<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><b>Final Notes<\/b><br \/>\nNow that we have completed developing the data tier of our REST API application, we are now ready to go back to continue working on the main REST API files.<br \/>\nIn the next tutorial, we would use REST request to perform GET, PUT, POST and DELETE operations on the actual data on the database.<\/p>\n<p>For now I would like to thank you for your efforts! You are doing great!<br \/>\nRemember to leave a comment if you have any challenge following this tutorial.<\/p>\n<p><ins style=\"display: block; text-align: center;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\"><\/ins><br \/>\n<ins style=\"display: block; text-align: center;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\"><\/ins><br \/>\n<ins style=\"display: block; text-align: center;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-format=\"fluid\" data-ad-layout=\"in-article\" data-ad-slot=\"8227894917\"><\/ins><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I will teach you how to generate your class diagram in Visual Studio. This is very interesting because I normally use Microsoft &hellip; <\/p>\n","protected":false},"author":2,"featured_media":746,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[289],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/122"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":3,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":1758,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions\/1758"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media\/746"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}