{"id":1981,"date":"2021-06-15T12:00:00","date_gmt":"2021-06-15T10:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/build-a-complete-app-with-asp-net-c-sql-lite-part-5\/"},"modified":"2026-07-06T18:42:28","modified_gmt":"2026-07-06T16:42:28","slug":"build-a-complete-app-with-asp-net-c-sql-lite-part-5","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/build-a-complete-app-with-asp-net-c-sql-lite-part-5\/","title":{"rendered":"Build a Complete App with ASP.Net, C#, SQL Lite \u2013 Part 5"},"content":{"rendered":"<p>In this part we would work on generating all our controllers. The code generator would help use\u00a0 do the following:<\/p>\n<ul>\n<li>generate the controller class<\/li>\n<li>create the methods<\/li>\n<li>generated the views<\/li>\n<\/ul>\n<p>Isn&#8217;t this amazing! We&#8217;ll\u00a0 be getting so much done with little or no code written. So let&#8217;s dive right in!<\/p>\n<ol>\n<li><a href=\"#t1\">Update Your Dependencies<\/a><\/li>\n<li><a href=\"#t2\">Create your Controllers<\/a><\/li>\n<li><a href=\"#t3\">Test and Fix Errors<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t1\">1. Update You Dependencies<\/strong><\/h5>\n<p>So far, everything have worked fine. Do you remember the version of Entity Framework we installed in<a href=\"https:\/\/kindsonthegenius.com\/blog\/build-a-complete-app-with-asp-net-c-sql-lite-part-3\/\" target=\"_blank\" rel=\"noopener\"> Part 3<\/a> ? It was 3.1.6. Now we would upgrade to 5.0.7 for all the three dependencies. Follow the steps below:<\/p>\n<p><strong>Step 1<\/strong> &#8211; Open Nugget Package Manager (right-click on the project and select Manage Nugget Packages)<\/p>\n<p><strong>Step 2<\/strong> &#8211; Click on the Installed tab. Then select each of the 3 packages and uninstall them.<\/p>\n<p><strong>Step 3<\/strong> &#8211; Follow the procedure in <a href=\"https:\/\/kindsonthegenius.com\/blog\/build-a-complete-app-with-asp-net-c-sql-lite-part-3\/\" target=\"_blank\" rel=\"noopener\">Part 3<\/a> and install them but this time use version 5.0.7.<\/p>\n<p><strong>Step 4<\/strong> &#8211; Finally, you need to install one more package: EnityFrameworkCore.SQLServer like so:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version <span style=\"color: #6600ee; font-weight: bold;\">5.0<\/span>.<span style=\"color: #6600ee; font-weight: bold;\">7<\/span>\r\n<\/pre>\n<p>Now we are ready to start adding the controllers.<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t2\">2. Create the Controllers<\/strong><\/h5>\n<p>We would create the controllers inside the Controllers folder. Let&#8217;s start with Rooms.<\/p>\n<p><strong>Step 1<\/strong> &#8211; Right-click on the Controllers folder and choose Add &gt; Controller<\/p>\n<figure id=\"attachment_14688\" aria-describedby=\"caption-attachment-14688\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14688\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding-300x185.jpg\" alt=\"Creating New Controller using Scaffolding\" width=\"300\" height=\"185\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding-300x185.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding-1024x632.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding-768x474.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding-600x371.jpg 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Creating-New-Controller-using-Scaffolding.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-14688\" class=\"wp-caption-text\">Creating New Controller using Scaffolding<\/figcaption><\/figure>\n<p><strong>Step 2<\/strong> &#8211; Select MVC Controller with view using Entity Framework and click on Add<\/p>\n<p><strong>Step 3<\/strong> &#8211; In the next window, specify the Data model, context and choose the layout. This is shown below. Then click on Add<\/p>\n<figure id=\"attachment_14689\" aria-describedby=\"caption-attachment-14689\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14689 size-medium\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller-300x192.jpg\" alt=\"Specify the Data model, context and layout\" width=\"300\" height=\"192\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller-300x192.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller-768x491.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller-600x384.jpg 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Specifty-the-Data-Model-and-Context-for-the-Room-Controller.jpg 991w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-14689\" class=\"wp-caption-text\">Specify the Data model, context and layout<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>After a some seconds, you will notice that the RoomsController class been generated for you. Also the Views have been generated in the Views folder.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Test and Fix Errors<\/strong><\/h4>\n<p>Lets&#8217; do some testing!<\/p>\n<p>Launch the application to make sure it works. Then navigate to \/rooms<\/p>\n<p>The rooms list view is displayed as shown below:<\/p>\n<figure id=\"attachment_14690\" aria-describedby=\"caption-attachment-14690\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14690\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View-300x195.jpg\" alt=\"Generated Rooms List View\" width=\"300\" height=\"195\" srcset=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View-300x195.jpg 300w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View-1024x667.jpg 1024w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View-768x500.jpg 768w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View-600x391.jpg 600w, https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2021\/06\/Rooms-List-View.jpg 1490w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-14690\" class=\"wp-caption-text\">Generated Rooms List View<\/figcaption><\/figure>\n<p>Now if you click on Create New or Edit, you&#8217;ll have an error page. To fix this follow the two steps below:<\/p>\n<p><strong>Step\u00a0 1<\/strong> &#8211; Open the _Layout.cshtml page in the Views\/Shared folder<\/p>\n<p><strong>Step 2<\/strong> &#8211; In the header section, adjust the &lt;link&gt; tag like so<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;link<\/span> <span style=\"color: #0000cc;\">href=<\/span><span style=\"background-color: #fff0f0;\">\"~\/css\/styles.css\"<\/span> <span style=\"color: #0000cc;\">rel=<\/span><span style=\"background-color: #fff0f0;\">\"stylesheet\"<\/span> <span style=\"color: #007700;\">\/&gt;<\/span>\r\n<\/pre>\n<p>(simply add ~\/ before the css)<\/p>\n<p><strong>Step 3<\/strong> &#8211; Scroll down to just before the &lt;\/body&gt; tag and add this code<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">@await RenderSectionAsync(\"Scripts\", required: false)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>At this point, you can launch the application and make sure it works well. Also try out Create New, Edit and Delete.<\/p>\n<p>Finally, go ahead to create other controllers (you can see the video). But it follows exactly the same procedure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this part we would work on generating all our controllers. The code generator would help use\u00a0 do the following: generate the controller class create &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[311],"tags":[],"class_list":["post-1981","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1981","targetHints":{"allow":["GET"]}}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1981"}],"version-history":[{"count":2,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1981\/revisions"}],"predecessor-version":[{"id":2199,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1981\/revisions\/2199"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}