tag:blogger.com,1999:blog-60826528351527985672024-03-28T00:58:12.790-07:00Sql server, .net and c# video tutorialFree C#, .Net and Sql server video tutorial for beginners and intermediate programmers.Unknownnoreply@blogger.comBlogger3103125tag:blogger.com,1999:blog-6082652835152798567.post-20295563411573249942021-03-23T13:20:00.007-07:002021-03-23T13:26:46.996-07:00Sql vs tsql vs plsql<p><span style="font-family: arial;">In this video we will understand the difference between SQL, T-SQL and PL/SQL.</span></p><p><span style="font-family: arial;">SQL stands for Structured Query Language. So, SQL is a language, specifically, it's a language for relational Databases.</span></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JYYoIypEC_76oYpwOqkC0_tDVhTfweSALR1bxHw5oFth-SomJkKxPt9QFEB1c7aO0QoskxCA8WNUg8kptiSwfq94JS8GqZcYP4FWJxks9n4kIKLd1UHj5dN59S0slibpPLNv7L1FKOLX/s1473/what-is-sql.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="what is sql" border="0" data-original-height="428" data-original-width="1473" height="93" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0JYYoIypEC_76oYpwOqkC0_tDVhTfweSALR1bxHw5oFth-SomJkKxPt9QFEB1c7aO0QoskxCA8WNUg8kptiSwfq94JS8GqZcYP4FWJxks9n4kIKLd1UHj5dN59S0slibpPLNv7L1FKOLX/w320-h93/what-is-sql.jpg" title="what is sql" width="320" /></a></div><h3 style="text-align: left;"><span style="font-family: arial;">What is a relational database and why do we use it</span></h3><p></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitQKxZQy3iW2Pf0sviYWYHN446WDE4ii_Z2xLN5X8spfUb8X7VitLtWxBRxGGPux_z30ePI8DK8QoeyLRgg1kqmpUKGxIqgw36GhMzf5xodYSyiw6D1HuF1TOjbnPa275UoZRIGA58g1RJ/s1448/what-is-relational-database.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="what is relational database" border="0" data-original-height="423" data-original-width="1448" height="93" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitQKxZQy3iW2Pf0sviYWYHN446WDE4ii_Z2xLN5X8spfUb8X7VitLtWxBRxGGPux_z30ePI8DK8QoeyLRgg1kqmpUKGxIqgw36GhMzf5xodYSyiw6D1HuF1TOjbnPa275UoZRIGA58g1RJ/w320-h93/what-is-relational-database.jpg" title="what is relational database" width="320" /></a></div><span style="font-family: arial;"><br />In simple terms a relational database is a collection of tables to store data. The tables are usually related to each other by primary and foreign key constraints</span><span style="font-family: arial;">, hence the term Relational Database Management System, in short RDBMS.</span><p></p><p><span style="font-family: arial;">For example, let's say we want to store our organisation Employees data. We create a database (EmployeesDB - I named it EmployeesDB, but you can give it any meaningful name you want) and in this database we create 3 tables.</span></p><p></p><ul style="text-align: left;"><li><span style="font-family: arial;">Departments - To store the list of all departments</span></li><li><span style="font-family: arial;">Gender - To store different genders (Male and Female for example)</span></li><li><span style="font-family: arial;">Employees - To store the list of all employees</span></li></ul><p></p>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!--Prasad AdUnit-->
<ins class="adsbygoogle" data-ad-client="ca-pub-6328538092426311" data-ad-format="auto" data-ad-slot="1864580310" data-full-width-responsive="true" style="display: block;"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p><span style="font-family: arial;">To create the database itself, tables, relationships and to insert, update, delete and even select data we use SQL - Structured Query Language. So, in simple terms, SQL is a database language, we use it on a Database to create database objects like tables, views, functions etc. We also use it to insert, update, delete and select data.</span></p><h3 style="text-align: left;"><span style="font-family: arial;">What is T-SQL and PL/SQL and how is it different SQL</span></h3><p><span style="font-family: arial;">Well you can think of SQL as a standard database language. It was initially developed by IBM and later ANSI (American National Standards Institute) made it a standard. So, SQL is an ANSI standard and based on it different database vendors like Microsoft, Oracle and many other organisations developed their own database query language.</span></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8fE9VAGiBexAfQeU9446QvCC6QwSjhcOH7k5ZQT7D9ofYz6VczxpEuH6Hr_XRda0T0ak3lJI-BxcCYFtlI6tPoJLTcJtZ3hbWRpbJ2FBmASwaOzAhhpUJXO_GbhdvAUUGF9iiQEWGB4W8/s1578/what-is-sql-with-example.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="what is sql with example" border="0" data-original-height="897" data-original-width="1578" height="182" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8fE9VAGiBexAfQeU9446QvCC6QwSjhcOH7k5ZQT7D9ofYz6VczxpEuH6Hr_XRda0T0ak3lJI-BxcCYFtlI6tPoJLTcJtZ3hbWRpbJ2FBmASwaOzAhhpUJXO_GbhdvAUUGF9iiQEWGB4W8/w320-h182/what-is-sql-with-example.jpg" title="what is sql with example" width="320" /></a></div><span style="font-family: arial;"><br />Standards are always good, because they allow us to write similar queries across different relational database management systems. Different vendors like Microsoft and Oracle for example, support most of the features of the ANSI SQL standard, however, these database vendors also include their own non-standard features that extend the standard SQL language.</span><p></p>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!--Prasad AdUnit-->
<ins class="adsbygoogle" data-ad-client="ca-pub-6328538092426311" data-ad-format="auto" data-ad-slot="1864580310" data-full-width-responsive="true" style="display: block;"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p><span style="font-family: arial;">So the database that is developed by Microsoft is called Microsoft SQL Server or MS SQL Server for short. The language that Microsoft developed to query SQL Server database is called Transact-SQL or T-SQL for short.</span></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqylKxGLU_yiThTAs5G0LewHYUgAkQbSLX-t1OYfgp8D3kdvdOQiSsc7-Qw1gQxt7ADHJ-l5ABwdBZnihSH0v-ct956wdzExmAqC80liQpLSz2SHxK91EaUyHhwcTpO69bW2dkvP9j0hUL/s1579/sql-vs-transact-sql.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="sql vs transact sql" border="0" data-original-height="649" data-original-width="1579" height="132" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqylKxGLU_yiThTAs5G0LewHYUgAkQbSLX-t1OYfgp8D3kdvdOQiSsc7-Qw1gQxt7ADHJ-l5ABwdBZnihSH0v-ct956wdzExmAqC80liQpLSz2SHxK91EaUyHhwcTpO69bW2dkvP9j0hUL/w320-h132/sql-vs-transact-sql.jpg" title="sql vs transact sql" width="320" /></a></div><span style="font-family: arial;"><br />Similarly Oracle corporation developed a database management system called Oracle and the language that we use to query oracle database is PL/SQL. By the way, PL stands for Procedural Language.</span><p></p><p><span style="font-family: arial;">So, you can think of SQL as a subset of T-SQL and PL/SQL. A word of caution here, both T-SQL and PL/SQL does not implement 100% of the feature set of standard SQL, but majority of the standard features are implemented. You can see that from the diagram below. Although, not entirely true, you can still think SQL is almost a subset of T-SQL and PL/SQL. This means if you know T-SQL or PL/SQL, then you already know the standard SQL.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrqQ8iFlEuh1rAuSC33VWlBD9UlayOxVoeLotSzysbELzcPYOGibhShgvJgh4IyeRUIMUxYLR3HEfwTGKSfmzZmoljPpRWx_afYNmx1H950hsxH-ihKySGL5Yrhj5cw1Rba2yfYccYp_Ly/s1370/Sql-vs-tsql-vs-plsql.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="Sql vs tsql vs plsql" border="0" data-original-height="604" data-original-width="1370" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrqQ8iFlEuh1rAuSC33VWlBD9UlayOxVoeLotSzysbELzcPYOGibhShgvJgh4IyeRUIMUxYLR3HEfwTGKSfmzZmoljPpRWx_afYNmx1H950hsxH-ihKySGL5Yrhj5cw1Rba2yfYccYp_Ly/w320-h141/Sql-vs-tsql-vs-plsql.jpg" title="Sql vs tsql vs plsql" width="320" /></a></div><br /><p><span style="font-family: arial;">The standard SQL is same across all database vendors. This means if you know the standard SQL, then you know how to do most of the basic things on most of the database management systems like SQL Server, Oracle, MySQL, PostgreSQL etc. If you ware wondering what is MySQL and PostgreSQL, well, just like SQL Server and Oracle, they are also relational database management systems.</span></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyRr7sLe7d5HAVzhuOVeN1So6j5l-ZNVbqCWstzGcPse_PKYUwmHtLJ5gVkvy4AHXg5j-Db6R5qFiLaCNbEAccTE20PqsR_yMnzlHIWd0V8skWP6cCu4Tf4OQ6HRwx6UBb4EVxRErvPwtT/s1500/what-is-t-sql.jpg" style="margin-left: 1em; margin-right: 1em;"><img alt="what is t-sql" border="0" data-original-height="327" data-original-width="1500" height="70" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyRr7sLe7d5HAVzhuOVeN1So6j5l-ZNVbqCWstzGcPse_PKYUwmHtLJ5gVkvy4AHXg5j-Db6R5qFiLaCNbEAccTE20PqsR_yMnzlHIWd0V8skWP6cCu4Tf4OQ6HRwx6UBb4EVxRErvPwtT/w320-h70/what-is-t-sql.jpg" title="what is t-sql" width="320" /></a></div>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!--Prasad AdUnit-->
<ins class="adsbygoogle" data-ad-client="ca-pub-6328538092426311" data-ad-format="auto" data-ad-slot="1864580310" data-full-width-responsive="true" style="display: block;"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<h3 style="text-align: left;"><span style="font-family: arial;">Summary</span></h3><p></p><p></p><ul style="text-align: left;"><li><span style="font-family: arial;">SQL is the standard database language</span></li><li><span style="font-family: arial;">Based on this standard SQL, database vendors like Microsoft, Oracle and many other organizations developed their own database query languages</span></li><li><span style="font-family: arial;">TSQL is a proprietary procedural language for working with Microsoft SQL Server database</span></li><li><span style="font-family: arial;">Similarly, PL/SQL is a proprietary procedural language for working with Oracle database</span></li><li><span style="font-family: arial;">T-SQL and PL/SQL are an extension to standard SQL. </span></li><li><span style="font-family: arial;">This means they have more features and functions than the standard SQL. </span></li><li><span style="font-family: arial;">For example, features such as local variables are added. Similarly many, many built-in functions are added for processing strings, numbers, dates and other types of data.</span></li><li><span style="font-family: arial;">They also added the capability to write stored procedures.</span></li></ul><p></p><p><span style="font-family: arial;">In short these procedural languages like T-SQL and PL/SQL for example, helps us in writing queries easier, quicker and more efficiently.</span></p><p><span style="font-family: arial;">If you want to learn SQL and T-SQL, please check out our <a href="https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB" target="_blank">SQL Server tutorial for beginners</a> course. We have covered everything you need, from the basics to advanced SQL concepts.</span>
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!--Prasad AdUnit-->
<ins class="adsbygoogle" data-ad-client="ca-pub-6328538092426311" data-ad-format="auto" data-ad-slot="1864580310" data-full-width-responsive="true" style="display: block;"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</p><h3 style="text-align: left;"><span style="font-family: arial;">SQL Scripts</span></h3><div><span style="font-family: arial;"><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">Database</span> EmployeesDB<br /><span style="color: blue;">Go</span><br /></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Use</span>
EmployeesDB<br /><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">table</span> Departments<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">table</span> Gender<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> Gender
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>20<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">table</span> Employees<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">),<br /></span> DeptId
<span style="color: blue;">int</span> <span style="color: blue;">foreign</span> <span style="color: blue;">key</span> <span style="color: blue;">references</span> Departments<span style="color: grey;">(</span>Id<span style="color: grey;">),<br /></span> GenderId
<span style="color: blue;">int</span> <span style="color: blue;">foreign</span> <span style="color: blue;">key</span> <span style="color: blue;">references</span> Gender<span style="color: grey;">(</span>Id<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Insert</span><span style="color: black;"> </span><span style="color: blue;">into</span><span style="color: black;"> Departments </span><span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'IT'</span><span style="color: grey;">)</span><br /><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Departments <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'HR'</span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Insert</span><span style="color: black;"> </span><span style="color: blue;">into</span><span style="color: black;"> Gender </span><span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Male'</span><span style="color: grey;">)</span><br /><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Gender <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Female'</span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Insert</span><span style="color: black;"> </span><span style="color: blue;">into</span><span style="color: black;"> Employees</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: black;">[Name]</span><span style="color: grey;">,</span><span style="color: black;"> DeptId</span><span style="color: grey;">,</span><span style="color: black;"> GenderId</span><span style="color: grey;">)</span><span style="color: black;"> </span><span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mark'</span><span style="color: grey;">,</span><span style="color: black;"> 1</span><span style="color: grey;">,</span><span style="color: black;"> 1</span><span style="color: grey;">)</span><br /><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees<span style="color: blue;"> </span><span style="color: grey;">(</span>[Name]<span style="color: grey;">,</span> DeptId<span style="color: grey;">,</span> GenderId<span style="color: grey;">)</span> <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mary'</span><span style="color: grey;">,</span> 1<span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees<span style="color: blue;"> </span><span style="color: grey;">(</span>[Name]<span style="color: grey;">,</span> DeptId<span style="color: grey;">,</span> GenderId<span style="color: grey;">)</span> <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'John'</span><span style="color: grey;">,</span> 2<span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees<span style="color: blue;"> </span><span style="color: grey;">(</span>[Name]<span style="color: grey;">,</span> DeptId<span style="color: grey;">,</span> GenderId<span style="color: grey;">)</span> <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Sara'</span><span style="color: grey;">,</span> 2<span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees<span style="color: blue;"> </span><span style="color: grey;">(</span>[Name]<span style="color: grey;">,</span> DeptId<span style="color: grey;">,</span> GenderId<span style="color: grey;">)</span> <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Steve'</span><span style="color: grey;">,</span> 2<span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Select</span><span style="color: black;"> </span><span style="color: grey;">*</span><span style="color: black;"> </span><span style="color: blue;">from</span> Departments<br /><span style="color: blue;">Select</span> <span style="color: grey;">*</span> <span style="color: blue;">from</span> Gender<br /><span style="color: blue;">Select</span> <span style="color: grey;">*</span> <span style="color: blue;">from</span> Employees </p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue;">Select</span><span style="color: black;">
Employees</span><span style="color: grey;">.</span><span style="color: blue;">Name</span><span style="color: black;"> </span><span style="color: blue;">as</span><span style="color: black;"> [Name]</span><span style="color: grey;">,</span><span style="color: black;"> Departments</span><span style="color: grey;">.</span><span style="color: blue;">Name</span><span style="color: black;"> </span><span style="color: blue;">as</span><span style="color: black;"> Department</span><span style="color: grey;">,</span><span style="color: black;"> Gender</span><span style="color: grey;">.</span><span style="color: black;">Gender </span><span style="color: blue;">as</span><span style="color: black;"> Gender<br /></span><span style="color: blue;">from</span>
Employees<br /><span style="color: grey;">join</span>
Departments <span style="color: blue;">on</span> Employees<span style="color: grey;">.</span>DeptId <span style="color: grey;">=</span> Departments<span style="color: grey;">.</span>Id<br /><span style="color: grey; line-height: 107%;">join</span><span style="line-height: 107%;"> Gender </span><span style="color: blue; line-height: 107%;">on</span><span style="line-height: 107%;"> Employees</span><span style="color: grey; line-height: 107%;">.</span><span style="line-height: 107%;">GenderId </span><span style="color: grey; line-height: 107%;">=</span><span style="line-height: 107%;"> Gender</span><span style="color: grey; line-height: 107%;">.</span><span style="line-height: 107%;">Id</span></p></span>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6082652835152798567.post-19311504405344939102021-03-20T05:17:00.002-07:002021-03-20T05:17:43.074-07:00Sql query to delete parent child rows<p><span style="font-family: arial;">In this video we will answer an interview question faced by one of our YouTube channel subscribers in a SQL Server Interview. To be able to answer this SQL question and any related follow up questions, you need to have a good understanding of</span></p><p></p><ul style="text-align: left;"><li><span style="font-family: arial;">Foreign Key Constraints</span></li><li><span style="font-family: arial;">Cascading Deletes and</span></li><li><span style="font-family: arial;">Transactions</span></li></ul><p></p><p><span style="font-family: arial;">We discussed these concepts in detail in our <a href="https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB" target="_blank">SQL Server tutorial for beginners</a> course. The following is the link.</span></p><p><span style="font-family: arial;"><a href="https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB">https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB</a></span></p><p><span style="font-family: arial;">The question in the interview goes like this - We have two tables - Table A and Table B. If I delete a row from table A, all the related rows in table B must also get deleted. How do we achieve this in SQL Server.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZw-bMyAbb4KzG-HfHFTmGq7Zt258zMNjGNProKfb1jGPznNqfD0WN9eorHI0yJLEp7vzzL_tJhAsA59fSs2h-mkxvB7V6RnClPDX1rBxa8zN3H_NG9XKs90VCoU7GkJ3um_EguLm4xNg1/s1304/sql-query-to-delete-parent-child-records.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sql query to delete parent child records" border="0" data-original-height="524" data-original-width="1304" height="130" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZw-bMyAbb4KzG-HfHFTmGq7Zt258zMNjGNProKfb1jGPznNqfD0WN9eorHI0yJLEp7vzzL_tJhAsA59fSs2h-mkxvB7V6RnClPDX1rBxa8zN3H_NG9XKs90VCoU7GkJ3um_EguLm4xNg1/w320-h130/sql-query-to-delete-parent-child-records.jpg" title="sql query to delete parent child records" width="320" /></a></div><br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p><span style="font-family: arial;">To give it a bit more context and clarity, instead of Table A and Table B, let's use Departments and Employees tables.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmHDkEl-TnhVTp0SkfojlN_Vx3jBnhLaukropclzEfDixFRKlNdsQFOKZbLwjsG7PM6ximIBeGM7mzWZdCiNOBnBpoG0iXA1Z2iMKsPz_SZz_6H6WDKMRa8SFU_AqcC1LLioEP2yxmnw4I/s1915/delete-from-multiple-tables-sql-server.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="delete from multiple tables sql server" border="0" data-original-height="846" data-original-width="1915" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmHDkEl-TnhVTp0SkfojlN_Vx3jBnhLaukropclzEfDixFRKlNdsQFOKZbLwjsG7PM6ximIBeGM7mzWZdCiNOBnBpoG0iXA1Z2iMKsPz_SZz_6H6WDKMRa8SFU_AqcC1LLioEP2yxmnw4I/w320-h141/delete-from-multiple-tables-sql-server.jpg" title="delete from multiple tables sql server" width="320" /></a></div><br /><p><span style="font-family: arial;">When a row from Departments table is deleted, all the related rows from the Employees table must also be deleted. For example, if we delete the IT department row from the Departments table, we also want all the employees of the IT department to be deleted from the Employees table as well.</span></p><h4 style="text-align: left;"><span style="font-family: arial;">Delete parent child rows in SQL</span></h4><p><span style="font-family: arial;"><span style="color: #2b00fe;">DeptId</span> column in the Employees table is a foreign key referencing <span style="color: #2b00fe;">Id</span> column in the Departments table.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgttbIUAgboKZyeKV5_4MR9QAMYPiUpd5SioeVFT7_xzPK4b_FwaWhSwPkiaLf_kpaKD8hJQVe22FgfsD8hDGWcSfc85QD9EH7ajrFPjSwhc5rVVCV7WZZghRL7ujEfiw2CbzXjQ6YHG8XE/s1341/sql-server-foreign-key-cascade-delete.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sql server foreign key cascade delete" border="0" data-original-height="498" data-original-width="1341" height="119" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgttbIUAgboKZyeKV5_4MR9QAMYPiUpd5SioeVFT7_xzPK4b_FwaWhSwPkiaLf_kpaKD8hJQVe22FgfsD8hDGWcSfc85QD9EH7ajrFPjSwhc5rVVCV7WZZghRL7ujEfiw2CbzXjQ6YHG8XE/w320-h119/sql-server-foreign-key-cascade-delete.jpg" title="sql server foreign key cascade delete" width="320" /></a></div><br /><p><span style="font-family: arial;">So, when a row is deleted from the Departments table, we also want all that department employees to be deleted from the Employees table. Considering the fact that DeptId is a foreign key, the correct way to achieve this is by enforcing cascade deletes.</span></p>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<h4 style="text-align: left;"><span style="font-family: arial;">Error - DELETE statement conflicted with the REFERENCE constraint</span></h4><p><span style="font-family: arial;">If we try to delete a row from the Departments table and if that department has related rows in the Employees table, by default, we get the following REFERENCE CONSTRAINT error</span></p><p><span style="font-family: arial;"><span style="color: red;">The DELETE statement conflicted with the REFERENCE constraint "FK__Employees__DeptI__38996AB5". The conflict occurred in database "TestDB", table "dbo.Employees", column 'DeptId'.</span></span></p><h4 style="text-align: left;"><span style="font-family: arial;">SQL Server Foreign Key Constraint Cascade Delete</span></h4><p><span style="font-family: arial;">First, drop the existing foreign key constraint</span></p><p><span style="font-family: arial;"><span style="color: #2b00fe;">Alter table Employees drop constraint Constraint_Name</span></span></p><p><span style="font-family: arial;">Recreate the foreign key constraint with cascading deletes</span></p><p><span style="color: #2b00fe;"><span style="font-family: arial;">Alter table Employees<br /></span><span style="font-family: arial;">add constraint FK_Dept_Employees_Cascade_Delete<br /></span><span style="font-family: arial;">foreign key (DeptId) references Departments(Id) on delete cascade</span></span></p><p><span style="font-family: arial;">With foreign key constraint cascade deletes in place, when we delete a row from the Departments table, all the related rows from the Employees table are also automatically deleted.</span></p><h4 style="text-align: left;"><span style="font-family: arial;">Same foreign key in multiple tables</span></h4><p><span style="font-family: arial;">What if we have the same foreign key in multiple tables? In the following example, in both the tables (Teachers and Students) GenderId is foreign key referencing Id column from the Gender table.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4GrVxrD1szlKB_DSgKjBBNy82VC4wmLfPXhADH2CG275tuPKSkKxCDwno-_TRNIJ9SyQMnV08nm-yaKL0-WRU89fFcRZDngwdx1skhqpWW9y47Ni_2n7U_ZuwLmWNNDYjYWfuS0XG8C7A/s1171/same-foreign-key-in-multiple-tables.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="same foreign key in multiple tables" border="0" data-original-height="955" data-original-width="1171" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4GrVxrD1szlKB_DSgKjBBNy82VC4wmLfPXhADH2CG275tuPKSkKxCDwno-_TRNIJ9SyQMnV08nm-yaKL0-WRU89fFcRZDngwdx1skhqpWW9y47Ni_2n7U_ZuwLmWNNDYjYWfuS0XG8C7A/w320-h261/same-foreign-key-in-multiple-tables.jpg" title="same foreign key in multiple tables" width="320" /></a></div><br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p><span style="font-family: arial;">Well, same idea, with foreign key cascading deletes on, when a row from the Gender table is deleted, all the related rows from both the tables (i.e Teachers and Students) are also deleted automatically.</span></p><h4 style="text-align: left;"><span style="font-family: arial;"><span style="color: red;">What if we do not have a foreign key constraint or we do not want to turn on cascade deletes</span></span></h4><p><span style="font-family: arial;">Well, in that case you can use a sql query like the following to do the deletes yourself. First delete the rows from the child tables and then from the parent table. We are using a SQL transaction to treat all the DELETE queries as one unit. All of the DELETES should succeed. If one of the DELETE query fails for some reason, rollback the transaction and UNDO the deletes.</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Begin</span> <span style="color: blue;">Try</span><o:p></o:p></span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: blue;">Begin</span> <span style="color: blue;">Tran</span> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: blue;">Declare</span> @GenderToDelete <span style="color: blue;">int</span> <span style="color: grey;">=</span> 2 </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: green;">-- Delete first from child tables<br /></span> <span style="color: blue;">Delete</span> <span style="color: blue;">from</span> Teachers <span style="color: blue;">where</span> GenderId
<span style="color: grey;">=</span> @GenderToDelete<br /> <span style="color: blue;">Delete</span> <span style="color: blue;">from</span> Students <span style="color: blue;">where</span> GenderId
<span style="color: grey;">=</span> @GenderToDelete </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: green;">-- Finally Delete from parent table<br /></span> <span style="color: blue;">Delete</span> <span style="color: blue;">from</span> Gender <span style="color: blue;">where</span> Id <span style="color: grey;">=</span> @GenderToDelete </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: blue;">Commit</span> <span style="color: blue;">Tran</span><br /><span style="color: blue;">End</span> <span style="color: blue;">Try</span> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Begin</span> <span style="color: blue;">Catch</span><o:p></o:p></span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"> <span style="color: blue;">Rollback</span> <span style="color: blue;">Tran</span><o:p></o:p></span></p><p>
</p><p class="MsoNormal"><span style="font-family: arial;"><span style="color: blue; line-height: 107%;">End</span><span style="line-height: 107%;"> </span><span style="color: blue; line-height: 107%;">Catch</span></span><o:p></o:p></p><p><span style="font-family: arial;">Please note : Always delete child records before deleting parent record, otherwise if a foreign key constraint is introduced later, your queries will start to fail.</span></p><h4 style="text-align: left;"><span style="font-family: arial;">SQL Script for tables (Departments and Employees)</span></h4><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span> <span style="color: blue;">table</span> Departments<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span> <span style="color: blue;">table</span> Employees<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">),<br /></span> DeptId
<span style="color: blue;">int</span> <span style="color: blue;">foreign</span> <span style="color: blue;">key</span> <span style="color: blue;">references</span> Departments<span style="color: grey;">(</span>Id<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Departments <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'IT'</span><span style="color: grey;">)</span><br /><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Departments <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'HR'</span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mark'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)</span><br /><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mary'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'John'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Employees <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Sara'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue; line-height: 107%;">Insert</span><span style="line-height: 107%;"> </span><span style="color: blue; line-height: 107%;">into</span><span style="line-height: 107%;"> Employees </span><span style="color: blue; line-height: 107%;">values
</span><span style="color: grey; line-height: 107%;">(</span><span style="color: red; line-height: 107%;">'Steve'</span><span style="color: grey; line-height: 107%;">,</span><span style="line-height: 107%;"> 2</span><span style="color: grey; line-height: 107%;">)</span></span></p>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<h4 style="text-align: left;"><span style="font-family: arial;">SQL Script for tables (Gender, Teachers and Students)</span></h4><p></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">table</span> Gender<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> Gender
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>20<span style="color: grey;">)<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span><span style="color: black;"> </span><span style="color: blue;">table</span> Teachers<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">),<br /></span> GenderId
<span style="color: blue;">int</span> <span style="color: blue;">foreign</span> <span style="color: blue;">key</span> <span style="color: blue;">references</span> Gender<span style="color: grey;">(</span>Id<span style="color: grey;">)</span> <span style="color: blue;">on</span> <span style="color: blue;">delete</span> <span style="color: blue;">cascade<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span> <span style="color: blue;">table</span> Students<br /><span style="color: grey;">(<br /></span> Id
<span style="color: blue;">int</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">identity</span><span style="color: grey;">,<br /></span> [Name]
<span style="color: blue;">nvarchar</span><span style="color: grey;">(</span>50<span style="color: grey;">),<br /></span> GenderId
<span style="color: blue;">int</span> <span style="color: blue;">foreign</span> <span style="color: blue;">key</span> <span style="color: blue;">references</span> Gender<span style="color: grey;">(</span>Id<span style="color: grey;">)</span> <span style="color: blue;">on</span> <span style="color: blue;">delete</span> <span style="color: blue;">cascade<br /></span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Gender <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Male'</span><span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Gender <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Female'</span><span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Teachers <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mark'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Teachers <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'John'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Teachers <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Mary'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Teachers <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Sara'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Teachers <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Flo'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Students <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'David'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Students <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Ron'</span><span style="color: grey;">,</span> 1<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Students <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Jess'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Students <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Tara'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> Students <span style="color: blue;">values </span><span style="color: grey;">(</span><span style="color: red;">'Innes'</span><span style="color: grey;">,</span> 2<span style="color: grey;">)<br /></span><span style="color: blue;">Go</span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Alter</span> <span style="color: blue;">table</span> Teachers<br /><span style="color: blue;">add</span> <span style="color: blue;">constraint</span> FK_Gender_Employees<br /><span style="color: blue;">foreign</span> <span style="color: blue;">key </span><span style="color: grey;">(</span>GenderId<span style="color: grey;">)</span> <span style="color: blue;">references</span> Gender<span style="color: grey;">(</span>Id<span style="color: grey;">)</span></span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Alter</span> <span style="color: blue;">table</span> Students<br /><span style="color: blue;">add</span> <span style="color: blue;">constraint</span> FK_Gender_Students<br /><span style="color: blue; line-height: 107%;">foreign</span><span style="line-height: 107%;"> </span><span style="color: blue; line-height: 107%;">key </span><span style="color: grey; line-height: 107%;">(</span><span style="line-height: 107%;">GenderId</span><span style="color: grey; line-height: 107%;">)</span><span style="line-height: 107%;"> </span><span style="color: blue; line-height: 107%;">references</span><span style="line-height: 107%;"> Gender</span><span style="color: grey; line-height: 107%;">(</span><span style="line-height: 107%;">Id</span><span style="color: grey; line-height: 107%;">)</span></span></p><p></p>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6082652835152798567.post-63247772150363607722020-10-24T15:13:00.003-07:002020-10-24T15:13:39.080-07:00How and why a sql inner left right full and even cross join returns the same row count<p><span style="font-family: arial;">We have 2 tables - TableA and TableB. Both the tables have just one column each. TableA has 2 rows and TableB has 3 rows.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLGEZU32Ex6Wt4Ci94-3KLp38x1Qha30HYpNwXc7PcwztXM9Q9MOB8pqM_qrkDCywJmB1wASkCiXkxBR-Ty1xNGslnanOXTflAUF5vqO1_-AxZYO6RLjZI82-pDOxONMndJJ2OMIsNoc7R/s368/sql-inner-join-cross-join-return-same-count-how.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sql inner join cross join return same count how" border="0" data-original-height="192" data-original-width="368" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLGEZU32Ex6Wt4Ci94-3KLp38x1Qha30HYpNwXc7PcwztXM9Q9MOB8pqM_qrkDCywJmB1wASkCiXkxBR-Ty1xNGslnanOXTflAUF5vqO1_-AxZYO6RLjZI82-pDOxONMndJJ2OMIsNoc7R/s16000/sql-inner-join-cross-join-return-same-count-how.jpg" title="sql inner join cross join return same count how" /></a></div><br /><p><span style="font-family: arial;">To join both these tables, we are using <span style="color: #2b00fe;">ColumnA</span> in <span style="color: #2b00fe;">TableA</span> and <span style="color: #2b00fe;">ColumnB</span> in <span style="color: #2b00fe;">TableB</span>. The following is the SQL Server interview question.</span></p><p><span style="font-family: arial;">No matter how you join these 2 tables, the query produces the same result i.e 6 rows - How and Why?</span></p><p></p><ol style="text-align: left;"><li><span style="font-family: arial;">Inner Join</span></li><li><span style="font-family: arial;">Left Outer Join</span></li><li><span style="font-family: arial;">Right Outer Join</span></li><li><span style="font-family: arial;">Full Outer Join OR</span></li><li><span style="font-family: arial;">even Cross Join</span></li></ol><p></p>
<div class="google-ad">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<h3 style="text-align: left;"><span style="font-family: arial;">SQL Script to create and populate the tables with test data</span></h3><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span> <span style="color: blue;">Table</span> TableA<br /></span><span style="font-family: arial;"><span style="color: grey;">(<br /></span></span><span style="font-family: arial;"> ColumnA
</span><span style="font-family: arial;"><span style="color: blue;">int<br /></span></span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Create</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">Table</span><span style="font-family: arial;"> TableB<br /></span><span style="font-family: arial;"><span style="color: grey;">(<br /></span></span><span style="font-family: arial;"> ColumnB
</span><span style="font-family: arial;"><span style="color: blue;">int<br /></span></span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableA </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableA </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> TableB <span style="color: blue;">Values </span><span style="color: grey;">(</span>1<span style="color: grey;">)</span><br /></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableB </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableB </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Select</span><span style="font-family: arial;"> ColumnA</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> ColumnB<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA<br /></span><span style="color: grey; font-family: arial;">inner</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">join</span><span style="font-family: arial;"> TableB<br /></span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Select</span><span style="font-family: arial;"> ColumnA</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> ColumnB<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA<br /></span><span style="color: grey; font-family: arial;">left</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">join</span><span style="font-family: arial;"> TableB<br /></span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Select</span><span style="font-family: arial;"> ColumnA</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> ColumnB<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA<br /></span><span style="color: grey; font-family: arial;">right</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">join</span><span style="font-family: arial;"> TableB<br /></span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Select</span><span style="font-family: arial;"> ColumnA</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> ColumnB<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA<br /></span><span style="color: blue; font-family: arial;">full</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">join</span><span style="font-family: arial;"> TableB<br /></span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Select</span> ColumnA<span style="color: grey;">,</span> ColumnB<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA<br /></span><span style="color: grey; font-family: arial; line-height: 107%;">cross</span><span style="font-family: arial; line-height: 107%;"> </span><span style="color: grey; font-family: arial; line-height: 107%;">join</span><span style="font-family: arial; line-height: 107%;"> TableB</span></p>
<div class="google-ad">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;">All the above queries return the same row count - 6 rows. How and why all the different types of joins return the same count of rows.</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4zG-aGTBC-RhRsTvFEfdcRRmos7XlugDO_vSrN_fztxw9c3A_JTIeBrB8-Uh3CTTlVN_H_aDp789fgHD8Xai_-g5888o5gJMs6Wvu3y2htNAb-vdrHNb_li6OiYl2VCaZM_m09-se5XYS/s337/sql-inner-left-right-join-same-results.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sql inner left right join same results" border="0" data-original-height="337" data-original-width="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4zG-aGTBC-RhRsTvFEfdcRRmos7XlugDO_vSrN_fztxw9c3A_JTIeBrB8-Uh3CTTlVN_H_aDp789fgHD8Xai_-g5888o5gJMs6Wvu3y2htNAb-vdrHNb_li6OiYl2VCaZM_m09-se5XYS/s16000/sql-inner-left-right-join-same-results.png" title="sql inner left right join same results" /></a></div><br /><p><span style="font-family: arial;">Every row in TableA matches with every row in TableB, so what we get back is a cartesian product i.e the number of rows in TableA multiplied by the number of rows in TableB. So, in essence it's like a cross join. </span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMXJboZd_ODnZO60GfNg-zDtiGdyRjOKVLhGrO2l0wdpurODUq5KiQhYFsdvGuuermAluVlPE6GE8lmJvTCp9w0E3g-ZkVbnfKs7NNMwafG3ik5DxbWtqefxWLFS7EvVx8eVg4Dk_x_JIk/s364/sql-inner-left-right-join-result-same-how.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sql inner left right join result same how" border="0" data-original-height="190" data-original-width="364" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMXJboZd_ODnZO60GfNg-zDtiGdyRjOKVLhGrO2l0wdpurODUq5KiQhYFsdvGuuermAluVlPE6GE8lmJvTCp9w0E3g-ZkVbnfKs7NNMwafG3ik5DxbWtqefxWLFS7EvVx8eVg4Dk_x_JIk/s16000/sql-inner-left-right-join-result-same-how.jpg" title="sql inner left right join result same how" /></a></div><br /><p><span style="font-family: arial;">TableA has 2 rows and TableB 3 rows. Every row in TableA matches with every row in TableB. So irrespective of the type of join we get the cartesian product 6, i.e 2 rows in TableA multiplied by 3 rows in TableB.</span></p><p><span style="color: red; font-family: arial;"><b>What do you think is the result going to be if we add one more row with a value of 1 to TableB.</b></span></p><p><span style="font-family: arial;">Well, the same logic, Cartesian product. 2 rows in TableA multiplied by 4 rows in TableB. So, the answer is 8.</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> TableA <span style="color: blue;">Values </span><span style="color: grey;">(</span>1<span style="color: grey;">)</span><br /><span style="color: blue;">Go</span></span></p><p class="MsoNormal"><o:p></o:p></p>
<div class="google-ad">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<p><span style="font-family: arial;">Execute all the 5 select queries again and you will get 8 rows as the result.</span></p><p><span style="font-family: arial;"><b>Are you still confused? Let's look at another example.</b></span></p><p><span style="font-family: arial;">Drop both the tables</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Drop</span> <span style="color: blue;">table</span> TableA<br /><span style="color: blue; line-height: 107%;">Drop</span><span style="line-height: 107%;"> </span><span style="color: blue; line-height: 107%;">table</span><span style="line-height: 107%;"> TableB</span></span></p><p class="MsoNormal"><o:p></o:p></p><p><span style="font-family: arial;">Recreate the tables. We now have a second column called SomeValue in both the tables.</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Create</span> <span style="color: blue;">Table</span> TableA<br /></span><span style="font-family: arial;"><span style="color: grey;">(<br /></span></span><span style="font-family: arial;"> </span><span style="font-family: arial;">ColumnA
</span><span style="color: blue; font-family: arial;">int</span><span style="font-family: arial;"><span style="color: grey;">,<br /></span></span><span style="font-family: arial;"> </span><span style="font-family: arial;">SomeValue
</span><span style="color: blue; font-family: arial;">nvarchar</span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">2</span><span style="color: grey; font-family: arial;">)<br /></span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Create</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">Table</span><span style="font-family: arial;"> TableB<br /></span><span style="font-family: arial;"><span style="color: grey;">(<br /></span></span><span style="font-family: arial;"> ColumnB
</span><span style="color: blue; font-family: arial;">int</span><span style="font-family: arial;"><span style="color: grey;">,<br /></span></span><span style="font-family: arial;"> SomeValue
</span><span style="color: blue; font-family: arial;">nvarchar</span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">2</span><span style="color: grey; font-family: arial;">)<br /></span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: arial;">--Insert test data.</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableA </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> </span><span style="color: red; font-family: arial;">'A1'</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableA </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> </span><span style="color: red; font-family: arial;">'A2'</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> TableB <span style="color: blue;">Values </span><span style="color: grey;">(</span>1<span style="color: grey;">,</span> <span style="color: red;">'B1'</span><span style="color: grey;">)</span><br /></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableB </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> </span><span style="color: red; font-family: arial;">'B2'</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Insert</span><span style="font-family: arial;"> </span><span style="color: blue; font-family: arial;">into</span><span style="font-family: arial;"> TableB </span><span style="color: blue; font-family: arial;">Values </span><span style="color: grey; font-family: arial;">(</span><span style="font-family: arial;">1</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> </span><span style="color: red; font-family: arial;">'B3'</span><span style="font-family: arial;"><span style="color: grey;">)<br /></span></span><span style="color: blue; font-family: arial;">Go</span></p><p class="MsoNormal"><o:p></o:p></p><p><span style="font-family: arial;">Now, the select queries. In addition to ColumnA and ColumnB we also want to select SomeValue From TableA. Let's give it an alias TableASomeValue. Similarly SomeValue column from TableB as well. Let's call it TableBSomeValue.</span></p><p><span style="font-family: arial;">Let's include the same select list on the rest of the 4 queries - that is left join, right join, full join, and cross join.</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Select</span> ColumnA<span style="color: grey;">,</span> ColumnB<span style="color: grey;">,</span> TableA<span style="color: grey;">.</span>SomeValue <span style="color: blue;">as</span> [TableASomeValue]<span style="color: grey;">,<br /></span></span><span style="font-family: arial;">TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;">
[TableBSomeValue]<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA </span><span style="color: grey; font-family: arial;">inner</span><span style="font-family: arial;"> </span><span style="font-family: arial;"><span style="color: grey;">join<br /></span></span><span style="font-family: arial;">TableB </span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Select</span> ColumnA<span style="color: grey;">,</span> ColumnB<span style="color: grey;">,</span> TableA<span style="color: grey;">.</span>SomeValue <span style="color: blue;">as</span> [TableASomeValue]<span style="color: grey;">,<br /></span></span><span style="font-family: arial;">TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;">
[TableBSomeValue]<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA </span><span style="color: grey; font-family: arial;">left</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="font-family: arial;"><span style="color: grey;">join<br /></span></span><span style="font-family: arial;">TableB </span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Select</span> ColumnA<span style="color: grey;">,</span> ColumnB<span style="color: grey;">,</span> TableA<span style="color: grey;">.</span>SomeValue <span style="color: blue;">as</span> [TableASomeValue]<span style="color: grey;">,<br /></span></span><span style="font-family: arial;">TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;">
[TableBSomeValue]<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA </span><span style="color: grey; font-family: arial;">right</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="font-family: arial;"><span style="color: grey;">join<br /></span></span><span style="font-family: arial;">TableB </span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span><span style="font-family: arial;"> </span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: arial;"><span style="color: blue;">Select</span> ColumnA<span style="color: grey;">,</span> ColumnB<span style="color: grey;">,</span> TableA<span style="color: grey;">.</span>SomeValue <span style="color: blue;">as</span> [TableASomeValue]<span style="color: grey;">,<br /></span></span><span style="font-family: arial;">TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;">
[TableBSomeValue]<br /></span><span style="color: blue; font-family: arial;">from</span><span style="font-family: arial;"> TableA </span><span style="color: blue; font-family: arial;">full</span><span style="font-family: arial;"> </span><span style="color: grey; font-family: arial;">outer</span><span style="font-family: arial;"> </span><span style="font-family: arial;"><span style="color: grey;">join<br /></span></span><span style="font-family: arial;">TableB </span><span style="color: blue; font-family: arial;">on</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnA </span><span style="color: grey; font-family: arial;">=</span><span style="font-family: arial;"> TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">ColumnB</span></p><p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: arial;">Select</span><span style="font-family: arial;"> ColumnA</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> ColumnB</span><span style="color: grey; font-family: arial;">,</span><span style="font-family: arial;"> TableA</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;"> [TableASomeValue]</span><span style="font-family: arial;"><span style="color: grey;">,<br /></span></span><span style="font-family: arial;">TableB</span><span style="color: grey; font-family: arial;">.</span><span style="font-family: arial;">SomeValue </span><span style="color: blue; font-family: arial;">as</span><span style="font-family: arial;">
[TableBSomeValue]<br /></span><span style="color: blue; font-family: arial; line-height: 107%;">from</span><span style="font-family: arial; line-height: 107%;"> TableA </span><span style="color: grey; font-family: arial; line-height: 107%;">cross</span><span style="font-family: arial; line-height: 107%;"> </span><span style="color: grey; font-family: arial; line-height: 107%;">join</span><span style="font-family: arial; line-height: 107%;"> TableB</span></p>
<div class="google-ad">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Prasad AdUnit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="1864580310"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<p class="MsoNormal"><o:p></o:p></p><p><span style="font-family: arial;">Execute all the queries. Notice the output. </span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBANWaED2fu36wy2EsPxyN8Vu97cfDpNoq0VShpldnRjMI6YyuOXUzRSEYgqemqFzn9MjDcg9mGx2IZx7M8V0B60N1rRTvMxhC5YhU0ovrFqmbHjam1GhHQYHmqTZ8Hgf5Tq0iG8v6qqfS/s895/all-sql-join-types-produce-same-result.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="all sql join types produce same result" border="0" data-original-height="289" data-original-width="895" height="103" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBANWaED2fu36wy2EsPxyN8Vu97cfDpNoq0VShpldnRjMI6YyuOXUzRSEYgqemqFzn9MjDcg9mGx2IZx7M8V0B60N1rRTvMxhC5YhU0ovrFqmbHjam1GhHQYHmqTZ8Hgf5Tq0iG8v6qqfS/w320-h103/all-sql-join-types-produce-same-result.jpg" title="all sql join types produce same result" width="320" /></a></div><br /><p><span style="font-family: arial;">It takes that first row in TableA, that is the the row which has the value A1 and returns every row in TableB, so we have A1B1, A1B2, A1B3. The same happends even with the second row in TableA. So we have A2B1, A2B2, A2B3.</span></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-64442663301247769602020-02-23T00:46:00.001-08:002020-02-23T00:46:28.577-08:00ASP.NET core razor pages course wrap up<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/DpLQYVErKm8" style="font-family: arial, helvetica, sans-serif;">Part 32 - Using stored procedure in entity framework core</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity_11.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/HHaCTg0kTbA">Part 33 - FromSqlRaw vs ExecuteSqlRaw in ASP.NET Core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/fromsqlraw-vs-executesqlraw-in-aspnet.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/fromsqlraw-vs-executesqlraw-in-aspnet_12.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/q2u1VY28Drs">Part 34 - Scaffolding CRUD Operations in ASP.NET Core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/scaffolding-crud-operations-in-aspnet.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/scaffolding-crud-operations-in-aspnet_17.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">This is Part 35 and the last video in this <a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhX6J31qad0wSO1N_rgGbOPV">ASP.NET core razor pages tutorial</a>.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Why use ASP.NET core razor pages framework</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">ASP.NET Core Razor Pages framework is a new technology to build page-focused web applications quicker and more efficiently with clean separation of concerns. Razor pages are introduced in .NET Core 2.0. It is lightweight, flexible and provides the developer the full control over the rendered HTML. </span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The recommendation from Microsoft is to use razor pages if we are building a Web UI (i.e web pages) and ASP.NET Core MVC if we are building a Web API. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Download source code and setup the project to run on your local machine</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Download the project source code from the following URL</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://drive.google.com/drive/folders/1z49q-8xkKu8N8VjdemYKTs_4IbzBeLWM?usp=sharing">https://drive.google.com/drive/folders/1z49q-8xkKu8N8VjdemYKTs_4IbzBeLWM?usp=sharing</a></span>
</div>
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Download <span style="color: #990000;">RazorPagesTutorial.rar</span> file.</span>
<br />
<br />
<img alt="razor pages project download" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiECabGhprGyRfLYeuE8yAOzza18Jhr7B1jW6uQb7ZlAZTiNMfbC54ieuQ9RsnrV3X5MeL3m_FAoijv85jYSl3UCPWq9uGrnqvSUeT1GW270F4pKdZY6jQMCDoVi4Tu2Mdv_jE6teAlxKpd/s1600/razor+pages+project+download.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Extract the project source code and open the solution file using Visual Studio 2019.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Execute the following command from Visual Studio Package Manager Console. Make sure you have selected the web project (RazorPagesTutorial) from the <span style="color: #990000;">Default project </span>dropdownlist. This creates the database and applies all the migrations.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">Update-Database</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">After the command completes, run the project using <span style="color: blue;">CTRL + F5</span></span>
<br />
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-6082652835152798567.post-38640282365328834932020-02-23T00:46:00.000-08:002020-02-23T00:46:23.412-08:00ASP.NET core razor pages course wrap up - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyPjZJliAGgPkxbjDeSlhD6493Mn_rx6EBjpJEl-PXXvNeierw5FJhPaA1tAkhyRvicq7P4k2S7e9TNIjr1KMjr6TvxtOb0RnFmM1K1-O5scnLugYn1TXCcBkJtvzBGJrJahkTgIyi5DgH/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyPjZJliAGgPkxbjDeSlhD6493Mn_rx6EBjpJEl-PXXvNeierw5FJhPaA1tAkhyRvicq7P4k2S7e9TNIjr1KMjr6TvxtOb0RnFmM1K1-O5scnLugYn1TXCcBkJtvzBGJrJahkTgIyi5DgH/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPF8kTyvLJ-OR15Io5aVeuv3QECZcY-Sx8i4gFe3W65gdGxl4payfQJQju8R1LjS7qODQUiITSqrWEERxLJ9rDg_A19Wbffg5qCd2m5Cyb8ko8IBoTy6wq8vb_KFdT6JI7S-4gRe3N8gL-/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPF8kTyvLJ-OR15Io5aVeuv3QECZcY-Sx8i4gFe3W65gdGxl4payfQJQju8R1LjS7qODQUiITSqrWEERxLJ9rDg_A19Wbffg5qCd2m5Cyb8ko8IBoTy6wq8vb_KFdT6JI7S-4gRe3N8gL-/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkVtSN-crhj_luVY42fdfeAabU2CdkaGv8gTktxQD-rhnrkMcI-joJ1xmsJCnp7B4OptpJOapFJRqaIuxkt_MFc41DX_rzKusAj2XHvJkf8gQUvDonp-UwsmUQyhzxz0O1o5_vdrWf7N_O/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkVtSN-crhj_luVY42fdfeAabU2CdkaGv8gTktxQD-rhnrkMcI-joJ1xmsJCnp7B4OptpJOapFJRqaIuxkt_MFc41DX_rzKusAj2XHvJkf8gQUvDonp-UwsmUQyhzxz0O1o5_vdrWf7N_O/s320/Slide3.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjzjAcIIWWKW9TCKk1HDkpUHyAkSspsgFig_krFxWcGD7x5kZLGw2izwQbMl0gEc2FZe0EtMrthOsdkdFiqeTmHR0TBo6O0vf_-XO8ic397ZDrVYUSlgpEY6Dwu68WZymeR6Ku2_7pkzPM/s1600/Slide4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjzjAcIIWWKW9TCKk1HDkpUHyAkSspsgFig_krFxWcGD7x5kZLGw2izwQbMl0gEc2FZe0EtMrthOsdkdFiqeTmHR0TBo6O0vf_-XO8ic397ZDrVYUSlgpEY6Dwu68WZymeR6Ku2_7pkzPM/s320/Slide4.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-53965206135439667472020-02-19T04:31:00.002-08:002022-11-02T21:31:08.543-07:00React Installation and Setup - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicnogkmEKrLaDBL6AC0U8S2be8IXfhDuzHmiZTkr79kmEaSskjSXO_JjSxa0QvbKkseETjixhSzrdPPMQdGDqDqTHNtTrPOb8tHxk9KMhtrRq_w5-Ak2Zptq394Sj66I4dSZ5dyd9nGLfj/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicnogkmEKrLaDBL6AC0U8S2be8IXfhDuzHmiZTkr79kmEaSskjSXO_JjSxa0QvbKkseETjixhSzrdPPMQdGDqDqTHNtTrPOb8tHxk9KMhtrRq_w5-Ak2Zptq394Sj66I4dSZ5dyd9nGLfj/s320/Slide1.PNG" width="320" /></a></div>
<hr/>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr/>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAYORFRHauL5NAIyQRkc9LmfVjy4yq1OICJN8-l9hStYSbi53JZiUhkpHeCsn5ETHD4yvcPAQJzfLNHHuZNHEQMV3L13pco2ASXukLOUe56x4P3shvPBfoeKaeoujyUpVVBdAas_7T_tFC/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAYORFRHauL5NAIyQRkc9LmfVjy4yq1OICJN8-l9hStYSbi53JZiUhkpHeCsn5ETHD4yvcPAQJzfLNHHuZNHEQMV3L13pco2ASXukLOUe56x4P3shvPBfoeKaeoujyUpVVBdAas_7T_tFC/s320/Slide2.PNG" width="320" /></a></div>
<hr/>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr/>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9rLXL1Y4zx178v9MlxLPqPwS7i_FA7N5ZMOYyODbPuvYiLa5EBQ9hZZiR99lt6bfOj4LlAi4eFGtK4TEhVgYYrqwKHEOL-Jk5KFb7ojwZjvB-7gQ63YtwT3QEjQ-j5cj_4Y3sWAgqg71/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9rLXL1Y4zx178v9MlxLPqPwS7i_FA7N5ZMOYyODbPuvYiLa5EBQ9hZZiR99lt6bfOj4LlAi4eFGtK4TEhVgYYrqwKHEOL-Jk5KFb7ojwZjvB-7gQ63YtwT3QEjQ-j5cj_4Y3sWAgqg71/s320/Slide3.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-66520163457548956872020-02-19T04:31:00.001-08:002020-02-19T04:31:47.196-08:00React Installation and Setup<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Suggested Videos</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/M9aaVZb1dCM">Part 1 - ReactJS Introduction</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/reactjs-introduction.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/reactjs-introduction-slides.html">Slides</a></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">For setting up React in our local system, first step is to Install <span style="color: blue;">NodeJs </span>and <span style="color: blue;">npm</span>.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Install Nodejs</b></span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Node.js provides a runtime environment to execute JavaScript code from outside a browser. NPM, Node package manager is used for managing and sharing the packages for either React or Angular. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">NPM will be installed along with Nodejs. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Node.js can be downloaded and installed from the official NodeJs website.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://nodejs.org/">https://nodejs.org</a></span>
</div>
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Once the Installation of Node is complete. Open Node.Js Command Prompt and we can check the Version as well.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Install Create-React-App Tool</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The next step is to install a tool called <span style="color: blue;">create-react-app</span> using NPM. This tool is used to create react applications easily from our system. You can install this at the system level or temporarily at a folder level. We will install it globally by using the following command.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">npm install -g create-react-app</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Creating a new react project</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">After <span style="color: blue;">create-react-app</span> is installed, we can create our first react application.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Lets say I want to create the project or application in <span style="background-color: #d0e0e3;">D:\React_Programs.</span></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">I will create this folder and let our command prompt point to it by using change directory command.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Lets create a new Project now using the command.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">create-react-app test-project</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Remember not to create the project with an upper case character In it.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Running the React Application</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Lets do cd to the Project we have created and run it locally on our system using <span style="color: blue;">npm start</span>. Launch the browser and visit <span style="color: blue;">http://localhost:3000</span>. We can then see our first React Application response in the browser. </span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">cd test-project</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">npm start</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We have created a New Project using React and executed the Project.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">But as a developer we would be more interested to know about the Project which is created, its structure and we would like to play around with it. So it is time for us to get an Editor. When we think of IDE, we have a variety of choices like Visual Studio Code, React IDE, Sublime Editor, Atom Editor, Webstorm and a few others. We will use <span style="color: blue;">VS Code</span> as our Editor.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Visual Studio Code is a free IDE from Microsoft built for developing and debugging web applications. It has integrated Git control & terminal. VS code’s IntelliSense allows Visual Studio Code to provide you with useful hints and auto-completion features while you code. So the next step is to Install Visual Studio Code.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Install Visual Studio Code</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Download and install Visual Studio Code from the following URL</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a></span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">After the installation, open the Project we have created earlier using VS Code. The Project has the following 3 folders</span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Node_modules</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Public</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">src</span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The output we have seen when the Project is executed comes from a file called <span style="color: blue;">Index.html </span>which resides inside <span style="color: blue;">public </span>folder.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In <span style="color: blue;">index.html </span>we have one div tag with id as root.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">div id</span><span style="color: red;">="root"</span><span style="color: blue;">></</span>div<span style="color: blue;">></span></span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">To understand the relation between the output we see and this index.html,</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Open <span style="color: blue;">src/app.js</span> file. </span><span style="font-family: "arial" , "helvetica" , sans-serif;">The image and the text we see in the browser are coming from here.</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Lets make a small change in the text, save it and lets have a look at the browser. We can see the changes and it happens very fast.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">How the index.html is linked to App.js will be discussed in our upcoming videos.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">With this we have the react environment setup on our local machine and we are ready to explore React.</span>
<br />
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">React online editors
</span></b><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Lets say we are in office, we have some free time and we’re interested in playing around with React, then you can use an online code playground like CodePen, CodeSandbox, or Glitch.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">For example, lets say we want to create react project using CodePen. In the browser, navigate to <a href="https://codepen.io/">https://codepen.io/</a> and click on <span style="background-color: #eeeeee;">Start Coding</span>.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Create a simple div in html section.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">div id</span><span style="color: red;">="root"</span><span style="color: blue;">></</span>div<span style="color: blue;">></span></span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Followed by writing some JavaScript Code :</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">ReactDOM.render(</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;"><</span><span style="color: #990000;">h1</span><span style="color: blue;">></span><span style="color: #cc0000;">Welcome to React World</span><span style="color: blue;"></</span><span style="color: #990000;">h1</span><span style="color: blue;">></span>,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> document.getElementById(<span style="color: #990000;">'root'</span>)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">);</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">This Code will throw an error as we are missing the references to two Javascript files.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Go to <span style="color: blue;">Pen Settings</span> section of Js and add,</span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">https://unpkg.com/react/umd/react.development.js</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">https://unpkg.com/react-dom/umd/react-dom.development.js</span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;">One script file refers to React and the other refers to ReactDOM which is the Virtual DOM introduced by React.</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Set the Javascript Preprocessor to Babel.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">With the above settings you should have the output produced as expected.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Babel is a free and open-source JavaScript transcompiler that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript that can be run by older JavaScript engines. Babel is a popular tool for using the newest features of the JavaScript programming language. More about Babel will be discussed in our upcoming videos.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">I hope we are clear on doing the React setup and creating our first Project using React.</span>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-9782619990713010422020-02-17T12:51:00.001-08:002020-02-17T12:51:33.571-08:00Scaffolding CRUD operations in asp.net core<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/uGfO14_9Czk" style="font-family: arial, helvetica, sans-serif;">Part 31 - Repository pattern in asp.net core razor pages</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor_10.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/DpLQYVErKm8">Part 32 - Using stored procedure in entity framework core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity_11.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/HHaCTg0kTbA">Part 33 - FromSqlRaw vs ExecuteSqlRaw in ASP.NET Core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/fromsqlraw-vs-executesqlraw-in-aspnet.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/fromsqlraw-vs-executesqlraw-in-aspnet_12.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>how to implement CRUD operations</b> (i.e Create, Read, Update and Delete) in ASP.NET core using visual studio scaffolding feature. This scaffolding feature generates the full set of CRUD pages. We can then modify and fine-tune these pages to meet our application specific requirements.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">To use the scaffolding tools you need 2 things</span>
<br />
<ol style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The Model class for which we want to scaffold the CRUD pages and</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The application <span style="color: #3d85c6;">DBContext </span>class that knows how to connect and work with the data in the underlying database</span></li>
</ol>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">ASP.NET Core Scaffolding Tools
</span></b>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the <b>Solution Explorer</b>, right click on the <b><span style="color: #cc0000;">Pages </span></b>folder or in a sub-folder in the Pages folder and select - <b><span style="color: #cc0000;">Add - New Scaffolded Item</span></b> from the context menu.
</span>
<br />
<br />
<img alt="asp.net core scaffolding" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXZdhzMTAhShT48W0Pz9n316IvvmH53rRUouIqgvd-UmQqDide7zEExFjQ4N2vGd-4Xv0NNGMs4X511VxXw11hpTFhLWMAp9qGWlCTN8nEzXMAe-HUyrAFkXcsdVlY3vArFqqUcEwNvhrE/s1600/asp.net+core+scaffolding.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the subsequent window, select <b>Razor Pages using Entity Framework (CRUD)</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Next, select the Model class and your application <span style="color: blue;">DBContext </span>class. Un-check <span style="color: blue;">Create a partial view</span>. Finally click the <span style="color: blue;">Add </span>button.
</span>
<br />
<br />
<img alt="asp.net core scaffold crud" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7nyP4Jk-eXjcsmlXWhebIMX_cp7VcmFlwToyy71NiKmYP2am3YDHTzA30q6CdXKvbaGKI6XwfXSjs1sV0EQ9XT3n-xTz9B6IuoI_h8E2szHQM4ezsz2fTEYisP0aYgwcLw-Xl7r1Hb6G8/s1600/asp.net+core+scaffold+crud.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Give it a few seconds and the fully functional CRUD pages are generated.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Validation attributes and scaffolding</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The code generated by the scaffolding tools will take the validation attributes (if present) into consideration and include the relevant tag helpers on the respective CRUD pages.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class</span> <span style="color: #3d85c6;">Employee</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public int </span>Id { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">Required</span>, <span style="color: #3d85c6;">MinLength</span>(3, ErrorMessage = <span style="color: #cc0000;">"Name must contain at least 3 characters"</span>)]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public string </span>Name { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">Required</span>]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">Display</span>(Name = <span style="color: #cc0000;">"Office Email"</span>)]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">RegularExpression</span>(@<span style="color: #cc0000;">"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"</span>,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> ErrorMessage = <span style="color: #cc0000;">"Invalid email format"</span>)]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public string </span>Email { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public string </span>PhotoPath { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">Required</span>]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span><span style="color: #3d85c6;">Dept</span>? Department { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">You can repeat this process for other model classes (i.e entities) in your application. This scaffolding feature saves lot of time.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Using the scaffolding feature we can also generate API and MVC controllers.</span>
<br />
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-56535727336039919542020-02-17T12:51:00.000-08:002020-02-17T12:51:25.478-08:00Scaffolding CRUD operations in asp.net core - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-XZB883FPGhZyScCCk4DWWqEbtLOE3MxmY3GD7-kZ5ykbta7eL1aY4C1Tz5lMTWirCyTiYKjVloeJ5TWDuqYe8-KWiAEOVfud9G8yrbEz03kp3nOZemJOLJidtZVL9ltxsQZ7ZjTan0Fy/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-XZB883FPGhZyScCCk4DWWqEbtLOE3MxmY3GD7-kZ5ykbta7eL1aY4C1Tz5lMTWirCyTiYKjVloeJ5TWDuqYe8-KWiAEOVfud9G8yrbEz03kp3nOZemJOLJidtZVL9ltxsQZ7ZjTan0Fy/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjPJSFYJWW6gKCgB5X7CsWAVpcG80sTVVWi5gJOIyWC3robD5t6PW4b6YI2oW3MoqG0PzPPDJYl_ujLXAeM5_fMpviACyjbcxwF3LnPfT_CWoo-9vVRfdK4K3iBgr7dVqcU_QiaM7cseKw/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjPJSFYJWW6gKCgB5X7CsWAVpcG80sTVVWi5gJOIyWC3robD5t6PW4b6YI2oW3MoqG0PzPPDJYl_ujLXAeM5_fMpviACyjbcxwF3LnPfT_CWoo-9vVRfdK4K3iBgr7dVqcU_QiaM7cseKw/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxEXC_vGad-bIEgQqEYPbhOIaecs9PTIIhhrylSbivMLN8lHhMc4-vhLZk6P8Hd9kNtkx9nsQuPLAXYgYAnwqttWjyozAqSxm2YV7F4GLMJBo6rF0atVZxykn46wgO0TYWVarS-F8DVEJk/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxEXC_vGad-bIEgQqEYPbhOIaecs9PTIIhhrylSbivMLN8lHhMc4-vhLZk6P8Hd9kNtkx9nsQuPLAXYgYAnwqttWjyozAqSxm2YV7F4GLMJBo6rF0atVZxykn46wgO0TYWVarS-F8DVEJk/s320/Slide3.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3NWZYhe0zdKk7wJKhn6vbjDQuwYQ38QG_E57XNoVbwWqLRrneAqnCFEN-ptAEXdfe0yd5k5FoE7Q6JlrXYK0SQbohU6Vt1a-jzuYIHylwodLfb62FBvcS_u5Mszr3Ng8UBZqAdVl32u3w/s1600/Slide4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3NWZYhe0zdKk7wJKhn6vbjDQuwYQ38QG_E57XNoVbwWqLRrneAqnCFEN-ptAEXdfe0yd5k5FoE7Q6JlrXYK0SQbohU6Vt1a-jzuYIHylwodLfb62FBvcS_u5Mszr3Ng8UBZqAdVl32u3w/s320/Slide4.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-47023677074428511322020-02-17T01:55:00.000-08:002020-02-17T01:55:46.352-08:00ReactJS Introduction - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5hkFSBgNJ6r1W1DRQkC2h-iLU85pQ8Qp3-AV6McRGWa2Q1_UornF1n9bQaULUwdWkE1MmSToXHvauzGPJKdImZB1zxfSit-cmCDCKaNrUeQemv7A1tzM0SRhGnv4QVPK74naqCIB3dEM-/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5hkFSBgNJ6r1W1DRQkC2h-iLU85pQ8Qp3-AV6McRGWa2Q1_UornF1n9bQaULUwdWkE1MmSToXHvauzGPJKdImZB1zxfSit-cmCDCKaNrUeQemv7A1tzM0SRhGnv4QVPK74naqCIB3dEM-/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDbxZvHAV0qjQQy5cUD76v1WcET9Z0EHij57R6xB0SeGNkEHxS-lXMOLIcyvxeIS28PrffKAHzeA4triHW_WtFYyXGXDFXJv1GFWCcnR-m3aZMcVDGRlbIhdshNn8mslFSqGhTF_DNEl3A/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDbxZvHAV0qjQQy5cUD76v1WcET9Z0EHij57R6xB0SeGNkEHxS-lXMOLIcyvxeIS28PrffKAHzeA4triHW_WtFYyXGXDFXJv1GFWCcnR-m3aZMcVDGRlbIhdshNn8mslFSqGhTF_DNEl3A/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidkmnCkPjrM69-wYppgccREDlw4d_CLChOX3tHLiNEgp1IkGvg0LShl0cwvyvGZeCii4Gm_I_6tbxy-FFNo9VfJb9Yz2UqDQLc0LgjG6TGA2q4x7xx4uUWAuoYmNZfLFhdAMAIc9mXdocF/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidkmnCkPjrM69-wYppgccREDlw4d_CLChOX3tHLiNEgp1IkGvg0LShl0cwvyvGZeCii4Gm_I_6tbxy-FFNo9VfJb9Yz2UqDQLc0LgjG6TGA2q4x7xx4uUWAuoYmNZfLFhdAMAIc9mXdocF/s320/Slide3.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAcKrmDstNPcP_BTQnGu_fq7pZ9NTycAQnJC9Y023aTDI1TxoToydc7FoHY1dybH25k85J239rFnOFvRXd_mhwbIJZL42SmQaZwiX_fbuJaioeAhnWYQznmNDvC5byNVgg9-TeCag08gp4/s1600/Slide4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAcKrmDstNPcP_BTQnGu_fq7pZ9NTycAQnJC9Y023aTDI1TxoToydc7FoHY1dybH25k85J239rFnOFvRXd_mhwbIJZL42SmQaZwiX_fbuJaioeAhnWYQznmNDvC5byNVgg9-TeCag08gp4/s320/Slide4.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL1-y-bmQCLmrq_otpFgciFpmvEWEUcdf1dtiNDHyeENXzL9T6Hjql_-ltUVzQ3BnEFvpEImf6hqszWUBPuOUmzFf1ZmMNdK9cBZ2su5kRiX8J0Ve9YKVzzPuM70GwGK_B-Lhpt3KqILPL/s1600/Slide5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL1-y-bmQCLmrq_otpFgciFpmvEWEUcdf1dtiNDHyeENXzL9T6Hjql_-ltUVzQ3BnEFvpEImf6hqszWUBPuOUmzFf1ZmMNdK9cBZ2su5kRiX8J0Ve9YKVzzPuM70GwGK_B-Lhpt3KqILPL/s320/Slide5.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-19068813074992611112020-02-17T01:50:00.002-08:002020-02-17T01:50:40.350-08:00ReactJS Introduction<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Suggested Video Tutorials</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/11/javascript-tutorial.html">JavaScript Tutorial</a></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2016/05/bootstrap-tutorial-for-beginners.html">Bootstrap Tutorial</a></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html">SQL Server Tutorial</a></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>In this ReactJS introduction we will learn</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">What is React</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">React journey so far</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Prerequisites to learn React </span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">React important features</span></li>
</ul>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>What is React</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>React is an Open Source JavaScript library</b> used for creating dynamic and interactive user interfaces for mobile and web applications. It is highly flexible, declarative and efficient for developing scalable, simple, and fast front-end for web & mobile applications. In simple terms, React JS effectively handles the view layer of mobile and web application.</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sreekanth Responsive Ad Unit -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="3198505994"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>React is flexible</b> in such a way that, in any application we can use as little or as much React as you need. For example, react can be used in any existing web application to develop a new feature or even the application’s entire UI.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>React is only concerned with rendering data to the Document Object Model (DOM)</b> and so creating React applications usually requires the use of additional libraries for implementing things like state management and routing which we will discuss in our upcoming videos.</span><br />
<br />
Ad
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>ReactJS has become highly popular </b>across the Globe because of its extra simplicity and flexibility. Many people are even referring to ReactJS as the future of web development.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Part of this huge popularity comes from the fact that top corporations such as Facebook, PayPal, Uber, Instagram, Airbnb etc use it to develop the user interfaces.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>React Journey</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">React was created by Jordan Walke, who is a software engineer at Facebook, It was first deployed on Facebook's News Feed in 2011 and later on Instagram in 2012. It was open-sourced at JSConf US in May 2013.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>React Native</b>, which enables native Android and iOS development with React, was announced at Facebook's React Conf in February 2015 and open-sourced in March 2015.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">On April 18, 2017, Facebook announced React Fiber, a new core algorithm of React library for building user interfaces. React Fiber was to become the foundation of any future improvements and feature development of the React library.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Like any other Library or Framework, even React has several versions as part of its evolution and 16.12 is the Current Release and we will discuss about the Various versions available in React and their important changes in our upcoming tutorials.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Prerequisites to learn React</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">HTML</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">CSS</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Knowledge of JavaScript and ES6(let and constant, classes and Arrow functions)</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Basic Knowledge of Node and npm</span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif;">We will discuss the basics of Node and NPM in our upcoming videos when we setup React</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>React features</b></span>
<br />
<br />
<img alt="react features" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguc-uoPnAuwij43g-ZrhVcmx2LcTyEB9CpVarSvLoHkd5yzwuYnP1_HhlsTIGOXFa7zT6KV-YgSC8w8h7FMrd3autx3Ox95ll20nVcslY9fuJmtG-JhKfS58H2espSfl6Rd8t5lSUgOrbv/s1600/React+features.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Virtual DOM : </b>The most important and biggest feature introduced by React is Virtual DOM. In react, as a developer we work with Virtual DOM inseatd of working directly with Real DOM. This will be discussed in our upcoming videos in detail.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Components : </b>In react, every application UI is broken down into Components. Component is the most basic building block of the Application UI. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>JSX :</b> JSX stands for Javascript Syntax Extension. React uses JSX for building templates instead of regular JavaScript. It is not necessary to use it when we are working with React but JSX makes React a lot more elegant. This feature makes it much better than many other frameworks out there today.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>One-way data binding :</b> React JS follows one-way data binding or unidirectional data flow that gives better control throughout the application.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>React Native : </b>React Native is an open-source mobile application framework while React is for websites(front-end). In React JS, React is the base abstraction of React DOM for the web platform, while with React Native, React is still the base abstraction but of React Native. So the syntax and workflow remain similar, but the components are different.</span>
</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6082652835152798567.post-27235605914589883642020-02-12T12:02:00.001-08:002020-02-12T12:02:16.537-08:00FromSqlRaw vs ExecuteSqlRaw in ASP.NET Core<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/hNPrD3tpeuI" style="font-family: arial, helvetica, sans-serif;">Part 30 - EF core migrations in razor pages project</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages_6.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/uGfO14_9Czk">Part 31 - Repository pattern in asp.net core razor pages</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor_10.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/DpLQYVErKm8">Part 32 - Using stored procedure in entity framework core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-stored-procedure-in-entity_11.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss the <b>difference between FromSqlRaw and ExecuteSqlRaw</b> and when to use one over the other.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>FromSqlRaw </b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We discussed the use of this method with an example in our <a href="https://youtu.be/DpLQYVErKm8">previous video</a> of this <a href="https://www.pragimtech.com/courses/asp-net-core-razor-pages-tutorial-for-beginners/">razor pages tutorial</a>. As the name implies this method is used to execute raw sql or stored procedures.</span><br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>ExecuteSqlRaw </b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">As the name implies, even this method is used to execute raw sql or stored procedures. So the obvious question is what's the difference and when to use one over the other.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>FromSqlRaw vs ExecuteSqlRaw</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Use <span style="color: blue;">FromSqlRaw </span>to execute a SQL query or stored procedure that returns entities. Use <span style="color: blue;">ExecuteSqlRaw </span>to execute a SQL query or stored procedure that performs database operations but does not return entities. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">For example to execute a sql query or stored procedure that returns list of employees use <span style="color: blue;">FromSqlRaw
</span></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public </span><span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> GetAllEmployees()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return </span>context.Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #cc0000;">"SELECT * FROM Employees"</span>)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Pass parameters to the query or stored procedure</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public </span><span style="color: #3d85c6;">Employee </span>GetEmployee(<span style="color: blue;">int </span>id)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return </span>context.Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #cc0000;">"spGetEmployeeById {0}"</span>, id)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Passing multiple parameters to the query or stored procedure</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">FromSqlRaw(<span style="color: blue;">string </span>sql, <span style="color: blue;">params object</span>[] parameters)</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The first parameter is the SQL to execute. The second parameter is the <span style="color: blue;">params </span>array, so we can pass multiple parameters by separating them with a comma.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public </span><span style="color: #3d85c6;">Employee </span>GetEmployee(<span style="color: blue;">int </span>p1, </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">int</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> p2, </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">int</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> p3)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"> return </span>context.Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #cc0000;">"spGetEmployeeById {0}, {1}, {2}"</span>, p1, p2, p3)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Passing parameters using SqlParameter</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public </span><span style="color: #3d85c6;">Employee </span>GetEmployee(<span style="color: blue;">int </span>id)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">SqlParameter </span>parameter = <span style="color: blue;">new </span><span style="color: #3d85c6;">SqlParameter</span>(<span style="color: #cc0000;">"@Id"</span>, id);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return </span>context.Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #cc0000;">"spGetEmployeeById @Id"</span>, parameter)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">SqlParameter </span>is in <span style="color: blue;">Microsoft.Data.SqlClient</span> namespace</span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Use <span style="color: blue;">ExecuteSqlRaw </span>to execute a SQL query or stored procedure that performs database operations but does not return entities. For example, if you want to execute insert, update or delete query or stored procedure use <span style="color: blue;">ExecuteSqlRaw </span>method.
</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public </span><span style="color: #3d85c6;">Employee </span>Add(<span style="color: #3d85c6;">Employee </span>newEmployee)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.Database.ExecuteSqlRaw(<span style="color: #cc0000;">"spInsertEmployee {0}, {1}, {2}, {3}"</span>,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee.Name,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee.Email,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee.PhotoPath,</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee.Department);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return </span>newEmployee;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Insert Stored procedure</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">Create Proc </span>spInsertEmployee</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">@Name <span style="color: blue;">nvarchar</span>(100),</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">@Email </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">nvarchar</span><span style="font-family: "arial" , "helvetica" , sans-serif;">(100),</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">@PhotoPath </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">nvarchar</span><span style="font-family: "arial" , "helvetica" , sans-serif;">(100),</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">@Dept <span style="color: blue;">int</span></span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">AS</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">BEGIN</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><span style="white-space: pre;"> </span>INSERT INTO</span> Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre;"> </span> (Name, Email, PhotoPath, Department)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre;"> </span> <span style="color: blue;">VALUES </span>(@Name, @Email, @PhotoPath, @Dept)</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">END</span>
</div>
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6082652835152798567.post-74017059340208929012020-02-12T12:02:00.000-08:002020-02-12T12:02:11.111-08:00FromSqlRaw vs ExecuteSqlRaw in ASP.NET Core - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifQHNj7Y8vXNQ7mdsP1HPzk1BO4HaN9h1TJbxrJMdeoZiaJ9gtwaCz9xIbeF3sgRVD-ZJwFdGpR4HgceS_zXbKfPhmsWL6Dyv-00SwiAaA8kBTkH5OgTK69XgezS6I4Iw8Ykk1sCl3gIOw/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifQHNj7Y8vXNQ7mdsP1HPzk1BO4HaN9h1TJbxrJMdeoZiaJ9gtwaCz9xIbeF3sgRVD-ZJwFdGpR4HgceS_zXbKfPhmsWL6Dyv-00SwiAaA8kBTkH5OgTK69XgezS6I4Iw8Ykk1sCl3gIOw/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjir_LFbJjAhtpwazKzhhZmOk9gKWlVeNHUC3vNPLKHJw4JNKM79oT8G3IxGk1v37kaLugpYLsi0KwtrBJCRAd5lVTbODMz8rbN-yI3lqfNjdsWvn2R-iKeCL-wXvGtTguRPh1bqIiI1ubv/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjir_LFbJjAhtpwazKzhhZmOk9gKWlVeNHUC3vNPLKHJw4JNKM79oT8G3IxGk1v37kaLugpYLsi0KwtrBJCRAd5lVTbODMz8rbN-yI3lqfNjdsWvn2R-iKeCL-wXvGtTguRPh1bqIiI1ubv/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-RYP9NAyYOEWg39bPfv9cTzVApH_UmXDDF92QgUVFOaol1a-hib1z8c2g0pY5kt9z-DZ_ThM1ZQZ4taAUI7eUVn-12y4omQ6gHvhBETq0mXOZlNhLuS9yzn5e2QkYPYoSFuCCIZtBrqL-/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-RYP9NAyYOEWg39bPfv9cTzVApH_UmXDDF92QgUVFOaol1a-hib1z8c2g0pY5kt9z-DZ_ThM1ZQZ4taAUI7eUVn-12y4omQ6gHvhBETq0mXOZlNhLuS9yzn5e2QkYPYoSFuCCIZtBrqL-/s320/Slide3.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7na2NRfbER6XwGpeCRhaWQPn-1GLFCPEmc3Fp2kArGmhnxn4mAg3R1QOGnqp3tqnOmy17y06NNasJrJbZ6YCcjcoCQv2wQ6V4SL1w4dqNK_fCr_rvq13UNMZPsfdzq3Y21oIy3rI5z5v/s1600/Slide4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7na2NRfbER6XwGpeCRhaWQPn-1GLFCPEmc3Fp2kArGmhnxn4mAg3R1QOGnqp3tqnOmy17y06NNasJrJbZ6YCcjcoCQv2wQ6V4SL1w4dqNK_fCr_rvq13UNMZPsfdzq3Y21oIy3rI5z5v/s320/Slide4.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJc6fA1qn8ceHv-YUJud-GegC9fdTsKC_UFJ46Xv7EDUvAOQctO4v7b4hKAvqkZjXevagJQagGEb0z5Uxu65EcwdiT4oaOCpjlLaYZx3vc0Btrp0WYQU0pw0p2he7zQYESclYa26UwoLf/s1600/Slide5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJc6fA1qn8ceHv-YUJud-GegC9fdTsKC_UFJ46Xv7EDUvAOQctO4v7b4hKAvqkZjXevagJQagGEb0z5Uxu65EcwdiT4oaOCpjlLaYZx3vc0Btrp0WYQU0pw0p2he7zQYESclYa26UwoLf/s320/Slide5.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-49697313116131814332020-02-11T13:34:00.001-08:002020-02-11T13:34:31.629-08:00Using stored procedure in entity framework core<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/PsyteV2jGjA" style="font-family: arial, helvetica, sans-serif;">Part 29 - Using sql server in razor pages project</a><span style="font-family: arial, helvetica, sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: arial, helvetica, sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project_5.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/hNPrD3tpeuI">Part 30 - EF core migrations in razor pages project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages_6.html">Slides</a></span>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://youtu.be/uGfO14_9Czk">Part 31 - Repository pattern in asp.net core razor pages</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/repository-pattern-in-aspnet-core-razor_10.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>how to use stored procedures with entity framework core</b>.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>EF Core FromSqlRaw Method</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">FromSqlRaw()</span> is one of the methods we can use to execute stored procedures from entity framework core. This method is also useful if the query can't be expressed using LINQ or when LINQ is not able to generate efficient SQL query.</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Creating stored procedure with database first approach</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">Create</span> <span style="color: blue;">Procedure</span> spGetEmployeeById</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">@Id <span style="color: blue;">int</span></span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">as</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">Begin</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><span style="white-space: pre;"> </span>Select</span> * <span style="color: blue;">from</span> Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre;"> </span><span style="color: blue;">Where</span> Id = @Id</span><br />
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">End</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">This procedures gets employee by id. You can create this procedure manually using SQL Server management studio, if you are using database first approach. </span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Creating stored procedure with code fist approach</b></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">If you are using code first approach we want this stored procedure to be created via the entity framework core migration.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the <span style="color: #3d85c6;">Package Manager Console</span>, execute the following command</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">Add-Migration</span> spGetEmployeeById
</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the generated <span style="color: #990000;">.cs</span> migration file, include the following code in the <span style="color: blue;">Up()</span> method
</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">protected override void</span> Up(<span style="color: #3d85c6;">MigrationBuilder</span> migrationBuilder)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">string</span> procedure = @<span style="color: #990000;">"Create Procedure spGetEmployeeById</span></span><br />
<span style="color: #990000; font-family: "arial" , "helvetica" , sans-serif;"> @Id int</span><br />
<span style="color: #990000; font-family: "arial" , "helvetica" , sans-serif;"> as</span><br />
<span style="color: #990000; font-family: "arial" , "helvetica" , sans-serif;"> Begin</span><br />
<span style="color: #990000; font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre;"> </span> Select * from Employees</span><br />
<span style="color: #990000; font-family: "arial" , "helvetica" , sans-serif;"><span style="white-space: pre;"> </span> Where Id = @Id</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #990000;"> End"</span>;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> migrationBuilder.Sql(procedure);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Include the following code in the <span style="color: blue;">Down()</span> method</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">protected override void</span> Down(<span style="color: #3d85c6;">MigrationBuilder</span> migrationBuilder)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">string</span> procedure = @<span style="color: #990000;">"Drop procedure spGetEmployeeById"</span>;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> migrationBuilder.Sql(procedure);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Execute the migration, using the following command. This creates the stored procedure in the database.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">Update-Database</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Call Stored Procedure using FromSqlRaw</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">{0} </span>is the parameter placeholder. While this syntax may look like String.Format syntax, the supplied value is treated like a parameter value and is not vulnerable to SQL injection.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee</span> GetEmployee(<span style="color: blue;">int</span> id)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> context.Employees</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #990000;">"spGetEmployeeById {0}"</span>, id)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-40245330571861738972020-02-11T13:34:00.000-08:002020-02-11T13:34:27.268-08:00Using stored procedure in entity framework core - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZg5Z_xn7vI4R4LSzCR3PhEf0friq4_d1AGz1rNteTZM3F1wCX_Xw47t6rvpPJwhEz33qmecuztvpTi4h9YjIxqWeknLNAHnKrlHdtML1Ad5ZvnncAb2RLE0zQJvtN6jGh2dhv4bAlV-CE/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZg5Z_xn7vI4R4LSzCR3PhEf0friq4_d1AGz1rNteTZM3F1wCX_Xw47t6rvpPJwhEz33qmecuztvpTi4h9YjIxqWeknLNAHnKrlHdtML1Ad5ZvnncAb2RLE0zQJvtN6jGh2dhv4bAlV-CE/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAFlfzurj6wWXZDOBYrnyNuatakrJx2XnkOMQ98HykaGpYZoHBBvqI2Tkv2S4kiCedFxliBgncAiWHA3xfv8ZAi6NS1sKdgUQO1O1RKMU-1444wr2tK1K1bGrJU-VLQo-YQrBux8UbqCaD/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAFlfzurj6wWXZDOBYrnyNuatakrJx2XnkOMQ98HykaGpYZoHBBvqI2Tkv2S4kiCedFxliBgncAiWHA3xfv8ZAi6NS1sKdgUQO1O1RKMU-1444wr2tK1K1bGrJU-VLQo-YQrBux8UbqCaD/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8fA2_RC0WrGMojZOe57NaBOhII_mRbtCk0YqHpsxqgGKkfbIsPllaT8xq-awmiLD8lVsGRX_0SoMj9lUn63LoQ-5GPU5h7lnXMvYooTGLZEg4X5YKrKwcfpJI5zlpXVY8njZ5Ys4032Wp/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8fA2_RC0WrGMojZOe57NaBOhII_mRbtCk0YqHpsxqgGKkfbIsPllaT8xq-awmiLD8lVsGRX_0SoMj9lUn63LoQ-5GPU5h7lnXMvYooTGLZEg4X5YKrKwcfpJI5zlpXVY8njZ5Ys4032Wp/s320/Slide3.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-27611528817941685902020-02-10T10:45:00.001-08:002020-02-10T10:45:55.351-08:00Repository pattern in asp.net core razor pages<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/qHwpZl1NEvI" style="font-family: arial, helvetica, sans-serif;">Part 28 - Install entity framework core in class library project</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_4.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_91.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/PsyteV2jGjA">Part 29 - Using sql server in razor pages project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project_5.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/hNPrD3tpeuI">Part 30 - EF core migrations in razor pages project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/ef-core-migrations-in-razor-pages_6.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>In this video, we will discuss </b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">What is Repository Pattern and it's benefits.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">An example that uses repository pattern in asp.net core razor pages project</span></li>
</ul>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>What is Repository Pattern</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Repository Pattern</b> is an abstraction of the Data Access Layer. It hides the details of how data is saved or retrieved from the underlying data source. The details of how data is stored and retrieved is in the respective repository. For example, you may have a repository that stores and retrieves data from an in-memory collection. You may have another repository that stores and retrieves data from a database like SQL Server. Yet, another repository that stores and retrieves data from an XML or CSV file.</span><br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class </span><span style="color: #3d85c6;">Employee</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public int </span>Id { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">public string</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Name { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">public string</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Email { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public string </span>PhotoPath { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span><span style="color: #3d85c6;">Dept</span>? Department { </span><span style="color: blue; font-family: "arial" , "helvetica" , sans-serif;">get; set;</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Repository Pattern Interface</b></span>
<br />
<ol style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The interface in the repository pattern specifies</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">What operations (i.e methods) are supported by the repository</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The data required for each of the operations i.e the parameters that need to be passed to the method and the data the method returns</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The repository interface contains what it can do, but not, how it does.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The implementation details are in the respective repository class that implements the repository Interface</span></li>
</ol>
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public interface </span><span style="color: #3d85c6;">IEmployeeRepository</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> GetAllEmployees();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> GetEmployee(<span style="color: blue;">int </span>id);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Add(</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Update(</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> updatedEmployee);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Delete(<span style="color: blue;">int </span>id);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">DeptHeadCount</span>> EmployeeCountByDept(<span style="color: #3d85c6;">Dept</span>? dept);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">> Search(<span style="color: blue;">string </span>searchTerm);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">IEmployeeRepository </span>interface supports the following operations</span>
<br />
<ol style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Get all the employees</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Get a single employee by id</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Add a new employee</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Updat an employee</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Delete an employee</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Get total count of employees by department</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Search and return a filtered list of employees</span></li>
</ol>
<span style="font-family: "arial" , "helvetica" , sans-serif;">The details of how these operations are implemented are in the repository class that implements this <span style="color: #3d85c6;">IEmployeeRepository </span>interface </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The following <span style="color: #3d85c6;">MockEmployeeRepository </span>class provides an implementation for <span style="color: #3d85c6;">IEmployeeRepository</span>. This specific implementation stores and retrieves employees from an in-memory collection.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">MockEmployeeRepository</span> : <span style="color: #3d85c6;">IEmployeeRepository</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">private</span> <span style="color: #3d85c6;">List</span><<span style="color: #3d85c6;">Employee</span>> _employeeList;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">MockEmployeeRepository</span>()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> _employeeList = <span style="color: blue;">new</span> <span style="color: #3d85c6;">List</span><<span style="color: #3d85c6;">Employee</span>>()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">new</span> <span style="color: #3d85c6;">Employee</span>() { Id = 1, Name = <span style="color: #a31515;">"Mary"</span>, Department = <span style="color: #3d85c6;">Dept</span>.HR,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Email = <span style="color: #a31515;">"mary@pragimtech.com"</span>, PhotoPath=<span style="color: #a31515;">"mary.png"</span> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">new</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">() { Id = 2, Name = <span style="color: #a31515;">"John"</span>, Department = </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;">.IT,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Email = <span style="color: #a31515;">"john@pragimtech.com"</span>, PhotoPath=<span style="color: #a31515;">"john.png"</span> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">new</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">() { Id = 3, Name = <span style="color: #a31515;">"Sara"</span>, Department = </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;">.IT,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Email = <span style="color: #a31515;">"sara@pragimtech.com"</span>, PhotoPath=<span style="color: #a31515;">"sara.png"</span> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">new</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">() { Id = 4, Name = <span style="color: #a31515;">"David"</span>, Department = </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;">.Payroll,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Email = <span style="color: #a31515;">"david@pragimtech.com"</span> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee </span>Add(</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> newEmployee.Id = _employeeList.Max(e => e.Id) + 1;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> _employeeList.Add(newEmployee);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> newEmployee;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Delete(<span style="color: blue;">int</span> id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> employeeToDelete =<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> _employeeList.FirstOrDefault(e => e.Id == id);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span> (employeeToDelete != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> _employeeList.Remove(employeeToDelete);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> employeeToDelete;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">DeptHeadCount</span>> EmployeeCountByDept(<span style="color: #3d85c6;">Dept</span>? dept)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">> query = _employeeList;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span>(dept.HasValue)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> query = query.Where(e => e.Department == dept.Value);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> query.GroupBy(e => e.Department)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .Select(g => <span style="color: blue;">new</span> DeptHeadCount()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Department = g.Key.Value,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Count = g.Count()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }).ToList();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">> GetAllEmployees()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> _employeeList;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> GetEmployee(<span style="color: blue;">int</span> id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> _employeeList.FirstOrDefault(e => e.Id == id);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;">> Search(<span style="color: blue;">string</span> searchTerm)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span>(<span style="color: blue;">string</span>.IsNullOrEmpty(searchTerm))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> _employeeList;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> _employeeList.Where(e => e.Name.Contains(searchTerm) ||<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> e.Email.Contains(searchTerm));<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> Update(</span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> updatedEmployee)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> employee = _employeeList<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault(e => e.Id == updatedEmployee.Id);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span> (employee != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> employee.Name = updatedEmployee.Name;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> employee.Email = updatedEmployee.Email;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> employee.Department = updatedEmployee.Department;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> employee.PhotoPath = updatedEmployee.PhotoPath;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> employee;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 13.5533px;"><span style="font-family: "arial" , "helvetica" , sans-serif;">}</span></span><o:p></o:p></div>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Repository Pattern - SQL Server Implementation</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">The following <span style="color: #3d85c6;">SQLEmployeeRepository </span>class provides another implementation for <span style="color: #3d85c6;">IEmployeeRepository</span>. This specific implementation stores and retrieves employees from a sql server database using entity framework core.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">SQLEmployeeRepository</span> : <span style="color: #3d85c6;">IEmployeeRepository</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">private</span> <span style="color: blue;">readonly</span> <span style="color: #3d85c6;">AppDbContext </span>context;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">SQLEmployeeRepository</span>(<span style="color: #3d85c6;">AppDbContext </span>context)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">this</span>.context = context;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee </span>Add(<span style="color: #3d85c6;">Employee </span>newEmployee)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.Employees.Add(newEmployee);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.SaveChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> newEmployee;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee </span>Delete(<span style="color: blue;">int</span> id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> employee = context.Employees.Find(id);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span>(employee != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.Employees.Remove(employee);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.SaveChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> employee;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">DeptHeadCount</span>> EmployeeCountByDept(<span style="color: #3d85c6;">Dept</span>? dept)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> query = context.Employees;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span> (dept.HasValue)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> query = query.Where(e => e.Department == dept.Value);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> query.GroupBy(e => e.Department)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .Select(g => <span style="color: blue;">new</span> DeptHeadCount()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Department = g.Key.Value,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Count = g.Count()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }).ToList();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> GetAllEmployees()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> context.Employees;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee </span>GetEmployee(<span style="color: blue;">int</span> id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> context.Employees<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FromSqlRaw<<span style="color: #3d85c6;">Employee</span>>(<span style="color: #a31515;">"spGetEmployeeById {0}"</span>, id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .ToList()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> .FirstOrDefault();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> Search(<span style="color: blue;">string</span> searchTerm)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">if</span> (<span style="color: blue;">string</span>.IsNullOrEmpty(searchTerm))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> context.Employees;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> context.Employees.Where(e => e.Name.Contains(searchTerm) ||<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> e.Email.Contains(searchTerm));<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public</span> <span style="color: #3d85c6;">Employee </span>Update(<span style="color: #3d85c6;">Employee </span>updatedEmployee)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">var</span> employee = context.Employees.Attach(updatedEmployee);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> employee.State = Microsoft.EntityFrameworkCore.<span style="color: #3d85c6;">EntityState</span>.Modified;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> context.SaveChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">return</span> updatedEmployee;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 13.5533px;"><span style="font-family: "arial" , "helvetica" , sans-serif;">}</span></span><o:p></o:p></div>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Which implementation to use</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Take a look at the following Index razor page. ASP.NET Core Dependency injection system injects an instance of <span style="color: #3d85c6;">IEmployeeRepository</span>.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class </span><span style="color: #3d85c6;">IndexModel </span>: <span style="color: #3d85c6;">PageModel</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"> private readonly </span><span style="color: #3d85c6;">IEmployeeRepository </span>employeeRepository;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> public <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> Employees { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> </span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> [<span style="color: #3d85c6;">BindProperty</span>(SupportsGet = <span style="color: blue;">true</span>)]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public string</span> SearchTerm { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span>IndexModel(<span style="color: #3d85c6;">IEmployeeRepository </span>employeeRepository)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">this</span>.employeeRepository = employeeRepository;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public void </span>OnGet()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Employees = employeeRepository.Search(SearchTerm);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">There are 2 implementations for <span style="color: #3d85c6;">IEmployeeRepository </span>interface. </span>
<br />
<ol style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">MockEmployeeRepository</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">SQLEmployeeRepository</span></li>
</ol>
<span style="font-family: "arial" , "helvetica" , sans-serif;">How does the application know which implementation to use. The answer to this is in <span style="color: #3d85c6;">Startup </span>class in Startup.cs file. With the following line of code, ASP.NET Core provides an instance of <span style="color: #3d85c6;">SQLEmployeeRepository </span>class when an instance of <span style="color: #3d85c6;">IEmployeeRepository </span>is requested. </span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public void</span> ConfigureServices(<span style="color: #3d85c6;">IServiceCollection </span>services)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="color: #6aa84f; font-family: "arial" , "helvetica" , sans-serif;"> // Rest of the code</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> services.AddScoped<<span style="color: #3d85c6;">IEmployeeRepository</span>, <span style="color: #3d85c6;">SQLEmployeeRepository</span>>();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We are using <span style="color: blue;">AddScoped()</span> method because we want the instance to be alive and available for the entire scope of the given HTTP request. For another new HTTP request, a new instance of <span style="color: #3d85c6;">SQLEmployeeRepository </span>class will be provided and it will be available throughout the entire scope of that HTTP request.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We discussed the difference between AddSingleton(), AddScoped() and AddTransient() methods in detail in <a href="https://youtu.be/v6Nr7Zman_Y">Part 44</a> of <a href="https://www.pragimtech.com/courses/asp-net-core-mvc-tutorial-for-beginners/">ASP.NET Core Tutorial</a>.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Throughout our entire application, in all the places where <span style="color: #3d85c6;">IEmployeeRepository </span>is injected an instance of <span style="color: #3d85c6;">SQLEmployeeRepository </span>is provided. If you want your application to use a different implementation instead, all you need to change is the following one line of code.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">services.AddScoped<<span style="color: #3d85c6;">IEmployeeRepository</span>, <span style="color: #3d85c6;">MockEmployeeRepository</span>>();
</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Benefits of Repository Pattern</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The code is cleaner, and easier to reuse and maintain.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Enables us to create loosely coupled systems. For example, if we want our application to work with oracle instead of sql server, implement an OracleRepository that knows how to read and write to Oracle database and register OracleRepository with the dependency injection system.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">In an unit testing project, it is easy to replace a real repository with a fake implementation for testing.</span></li>
</ul>
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-6082652835152798567.post-69613295371929826182020-02-10T10:45:00.000-08:002020-02-10T10:45:49.324-08:00Repository pattern in asp.net core razor pages - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG7sz6a9_iDWJZ8hZLzqR5FA8cix5xcuvIciCM9KrHR5qr9PShpnK96Ot9iF9M7GZPkLQTPSCusj-tjUnVk8rOwFP0N6-DQGYHNSSMtQN25OoZKUIcofBvPT0c_Reu_lU21ZIHFq43la9k/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG7sz6a9_iDWJZ8hZLzqR5FA8cix5xcuvIciCM9KrHR5qr9PShpnK96Ot9iF9M7GZPkLQTPSCusj-tjUnVk8rOwFP0N6-DQGYHNSSMtQN25OoZKUIcofBvPT0c_Reu_lU21ZIHFq43la9k/s320/Slide1.PNG" width="320" /></a></div>
<hr/>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr/>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNJYg6pDCSzjlRBIdsqmX6_dAbCU4amSVotCBUCsU7g3PQEQuqErO-JEnbGc22Ak9x-ejDwnCBt4hWmeLPJgrbDT9VwOzsBPoj0E5Omy1mOhGsFVyvR006y4N_vrn27qiRHQNFnLkXDREe/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNJYg6pDCSzjlRBIdsqmX6_dAbCU4amSVotCBUCsU7g3PQEQuqErO-JEnbGc22Ak9x-ejDwnCBt4hWmeLPJgrbDT9VwOzsBPoj0E5Omy1mOhGsFVyvR006y4N_vrn27qiRHQNFnLkXDREe/s320/Slide2.PNG" width="320" /></a></div>
<hr/>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr/>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-71640965002549743642020-02-06T11:30:00.001-08:002020-02-06T11:30:59.279-08:00EF core migrations in razor pages project<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/gb6TMtoGQEM" style="font-family: arial, helvetica, sans-serif;">Part 27 - Implement search page in ASP.NET Core</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/qHwpZl1NEvI">Part 28 - Install entity framework core in class library project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_4.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_91.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/PsyteV2jGjA">Part 29 - Using sql server in razor pages project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/using-sql-server-in-razor-pages-project_5.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>creating and executing EF core migrations in a razor pages project</b>.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>What is a migration in entity framework core </b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Migration is an entity framework core feature that keeps the database schema and our application model classes (also called entity classes) in sync.</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Creating a migration</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">If you are using Visual Studio like me, then use <span style="color: blue;">Package Manager Console</span>. To launch Package Manager Console in Visual Studio, click on <span style="color: blue;">View - Other Windows - Package Manager Console</span></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the <span style="color: blue;">Package Manager Console</span> window, please make sure you have selected the project in which you want the migration to be created. In our case, we created our data access project using a separate class library project <span style="color: blue;">(RazorPagesTutorial.Services)</span>. So please make sure this project is selected from the <span style="color: blue;">Default project</span> dropdownlist.</span>
<br />
<br />
<img alt="ef core migrations in razor pages project" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKd8DLzVlsTpa2qyXjDxEgtiy6r0sMINd2_F6uzMawhOz9NPHaXPsasoEe3DDFDUCn_nxXLGibB4UXyohaFZGtegkTOzd7ZPl2tD7WHaBpgTqdwBNlAZLScwoA9DYL2jQJ6NPFT_LiJEQ4/s1600/EF+core+migrations+in+razor+pages+project.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Use <i style="background-color: #eeeeee;">Add-Migration</i> command to create a migration. The following command creates the initial migration. <i style="background-color: #eeeeee;">InitialCreate </i>is the name of the migration.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">Add-Migration InitialCreate</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">When the above command completes, you will see a file in the <span style="color: blue;">"Migrations"</span> folder that ends with the name <span style="color: blue;">InitialCreate.cs.</span> This file has the code required to create the respective database tables.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>Please note : </b>To have the command auto-completed in the Package Manager Console window, type part of the command and press the TAB key.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Executing a migration</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We need to execute the migration code to create the tables. If the database does not exist already, it creates the database and then the database tables. For updating the database, we use <span style="color: blue;">Update-Database</span> command. To the <span style="color: blue;">Update-Database </span>command we may pass the migration name we want to execute. If no migration is specified, the command by default executes the last migration.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We can confirm that the database and the required tables are created using SQL Server Object Explorer window in Visual Studio.</span>
<br />
<br />
<img alt="ef core migrations tutorial" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6Lm3f9lU20-J9KWMOz4ogfxFuFSmMDEiBa_pD0Vn_GD7zjCn9ANxRRsv5fb5BQ5QL3MUCAOM3woFrTvlRdNr9tB07ATux5Y-UFi-nvt_lL_qwRynR9b3hYVAdwoRlmGrU9KloA3gLVMVC/s1600/ef+core+migrations+tutorial.png" />
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">At the moment our application is still using <span style="color: #3d85c6;">MockEmployeeRepository </span>which is an in-memory collection of employees. In our upcoming videos we will implement <span style="color: #3d85c6;">SQLRepository </span>which stores and retrieves employees from sql server employees table that we have just created.
</span>
<br />
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-67485555704448953022020-02-06T11:30:00.000-08:002020-02-06T11:30:53.410-08:00EF core migrations in razor pages project - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnmVzo-CYwJnl5CNAUMAIaeizlcLWSzL_kDc6t3E509U7CT0DYdQn-V61eoLl7JnCglzQ1BZUv2Xy5L9jxsLxiLQlWNklSVt7bTUKtGez7YnP3NtN2s3Qp1YrRLyauqG2DKzPMasvfNcVv/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnmVzo-CYwJnl5CNAUMAIaeizlcLWSzL_kDc6t3E509U7CT0DYdQn-V61eoLl7JnCglzQ1BZUv2Xy5L9jxsLxiLQlWNklSVt7bTUKtGez7YnP3NtN2s3Qp1YrRLyauqG2DKzPMasvfNcVv/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwzAS93DipwbemDvDKf5K3bT3d7Epvr1l6cuJtsAnfQ8RGqOHeXgIbZGQYcMaLYtl2C1ryAM2F3kWmU2e4U3Ssc6Kq0lOd_u-Wy_zyYIulg3Y084JIjNCxqkl2tC-eHOTTI0nwUZbWIjy8/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwzAS93DipwbemDvDKf5K3bT3d7Epvr1l6cuJtsAnfQ8RGqOHeXgIbZGQYcMaLYtl2C1ryAM2F3kWmU2e4U3Ssc6Kq0lOd_u-Wy_zyYIulg3Y084JIjNCxqkl2tC-eHOTTI0nwUZbWIjy8/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihCmvZs02hzjL47VycsMuLZ_NoNxt3nouyyIOp_zfcxJlKn9-m5BrRJejhMBX-d9A5hT_a1JTwiF7S8_dsCCJeEj9Gj1cS13dU5aEtjKebtUVJIjekwltg_ck-N9cAtxddy8VZBNnYmGAu/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihCmvZs02hzjL47VycsMuLZ_NoNxt3nouyyIOp_zfcxJlKn9-m5BrRJejhMBX-d9A5hT_a1JTwiF7S8_dsCCJeEj9Gj1cS13dU5aEtjKebtUVJIjekwltg_ck-N9cAtxddy8VZBNnYmGAu/s320/Slide3.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-49094491543236897582020-02-05T12:00:00.001-08:002020-02-05T12:00:17.227-08:00Using sql server in razor pages project<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/thRoRKHdtg8" style="font-family: arial, helvetica, sans-serif;">Part 26 - ASP.NET Core view component tag helper</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper_30.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/gb6TMtoGQEM">Part 27 - Implement search page in ASP.NET Core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/qHwpZl1NEvI">Part 28 - Install entity framework core in class library project</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_4.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/install-entity-framework-core-in-class_91.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>how to configure and use SQL Server with entity framework core in ASP.NET Core razor pages project</b>.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">One of the very important classes in Entity Framework Core is the <span style="color: #3d85c6;">DbContext </span>class. This is the class that we use in our application code to interact with the underlying database. It is this class that manages the database connection and is used to retrieve and save data in the database.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">To use the DbContext class in our application</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">We create a class that derives from the DbContext class.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">DbContext class is in Microsoft.EntityFrameworkCore namespace.</span></li>
</ul>
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class </span><span style="color: #3d85c6;">AppDbContext </span>: <span style="color: #3d85c6;">DbContext</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{ }</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>DbContextOptions in Entity Framework Core</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">For the <span style="color: #3d85c6;">DbContext </span>class to be able to do any useful work, it needs an instance of the <span style="color: #3d85c6;">DbContextOptions </span>class.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The <span style="color: #3d85c6;">DbContextOptions </span>instance carries configuration information such as the connection string, database provider to use etc.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">To pass the <span style="color: #3d85c6;">DbContextOptions </span>instance we use the constructor as shown in the example below.</span></li>
</ul>
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class</span> <span style="color: #3d85c6;">AppDbContext </span>: <span style="color: #3d85c6;">DbContext</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span>AppDbContext(<span style="color: #3d85c6;">DbContextOptions</span><<span style="color: #3d85c6;">AppDbContext</span>> options)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> : <span style="color: blue;">base</span>(options)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Entity Framework Core DbSet</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The <span style="color: #3d85c6;">DbContext </span>class includes a <span style="color: #3d85c6;">DbSet</span><<span style="color: #3d85c6;">TEntity</span>> property for each entity in the model.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">At the moment in our application we have, only one entity class - <span style="color: #3d85c6;">Employee</span>.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">So in our <span style="color: #3d85c6;">AppDbContext </span>class we only have one <span style="color: #3d85c6;">DbSet</span><<span style="color: #3d85c6;">Employee</span>> property.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">We will use this <span style="color: #3d85c6;">DbSet </span>property <span style="color: #3d85c6;">Employees </span>to query and save instances of the <span style="color: #3d85c6;">Employee </span>class.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The LINQ queries against the <span style="color: #3d85c6;">DbSet</span><<span style="color: #3d85c6;">TEntity</span>> will be translated into queries against the un<span style="color: blue;">derlying database.</span></span></li>
</ul>
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class</span> <span style="color: #3d85c6;">AppDbContext </span>: <span style="color: #3d85c6;">DbContext</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span>AppDbContext(<span style="color: #3d85c6;">DbContextOptions</span><<span style="color: #3d85c6;">AppDbContext</span>> options)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> : <span style="color: blue;">base</span>(options)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span>
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span><span style="color: #3d85c6;">DbSet</span><<span style="color: #3d85c6;">Employee</span>> Employees { <span style="color: blue;">get; set;</span> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Database Connection String in ASP.NET Core</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We are using SQL Server localdb which is automatically installed along with Visual Studio. If you want to use a full blown SQL Server instead of localdb, simply change the connection string in <span style="color: #990000;">appsettings.json</span> configuration file to point to your instance of SQL Server.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">During development database connection string is stored in <span style="color: #990000;">appsettings.json</span> file.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: #3d85c6;">"ConnectionStrings"</span>: {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">"EmployeeDBConnection"</span>: <span style="color: #990000;">"server=(localdb)\\MSSQLLocalDB;database=HRDB;Integrated Security=true"</span></span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Add SQL Server and Entity Framework Services</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public class</span> <span style="color: #3d85c6;">Startup</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span>Startup(<span style="color: #3d85c6;">IConfiguration </span>configuration)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Configuration = configuration;</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public </span><span style="color: #3d85c6;">IConfiguration </span>Configuration { <span style="color: blue;">get;</span> }</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: blue;">public void </span>ConfigureServices(<span style="color: #3d85c6;">IServiceCollection </span>services)</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> {</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <i><b>services.AddDbContextPool<<span style="color: #3d85c6;">AppDbContext</span>>( options => </b></i></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><i><b>options.UseSqlServer(Configuration.GetConnectionString(<span style="color: #990000;">"EmployeeDBConnection"</span>)));</b></i></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> services.AddRazorPages();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> services.AddSingleton<<span style="color: #3d85c6;">IEmployeeRepository</span>, <span style="color: #3d85c6;">MockEmployeeRepository</span>>();</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> }</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">We want to configure and use Microsoft SQL Server with entity framework core.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">We usually specify this configuration in <span style="color: blue;">ConfigureServices()</span> method in Startup.cs file.</span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Difference between AddDbContext() and AddDbContextPool() methods</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">We can use either <span style="color: blue;">AddDbContext()</span> or <span style="color: blue;">AddDbContextPool()</span><span style="color: yellow;"> </span>method to register our application specific <span style="color: #3d85c6;">DbContext </span>class with the ASP.NET Core dependency injection system.</span></span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">The difference is, <span style="color: blue;">AddDbContextPool()</span> method provides DbContext pooling.</span></span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">With DbContext pooling, an instance from the DbContext pool is provided if available, rather than creating a new instance.</span></span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">DbContext pooling is conceptually similar to how connection pooling works in ADO.NET.</span></span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;">From a performance standpoint <span style="color: blue;">AddDbContextPool() </span>method is better over <span style="color: blue;">AddDbContext() </span>method.</span></span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">AddDbContextPool()</span> method is introduced in ASP.NET Core 2.0. So if you are using ASP.NET Core 2.0 or later use <span style="color: blue;">AddDbContextPool()</span> method over <span style="color: blue;">AddDbContext() </span>method.</span></span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>UseSqlServer() Extension Method</b></span>
<br />
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">UseSqlServer()</span> extension method is used to configure our application specific <span style="color: #3d85c6;">DbContext </span>class to use Microsoft SQL Server as the database.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">To connect to a database, we need the database connection string which is provided as a parameter to <span style="color: blue;">UseSqlServer()</span> extension method.</span></li>
</ul>
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">services.AddDbContextPool<<span style="color: #3d85c6;">AppDbContext</span>>(</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> options => options.UseSqlServer(Configuration.GetConnectionString(<span style="color: #990000;">"EmployeeDBConnection"</span>)));</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">At the moment our application is still using <span style="color: #3d85c6;">MockEmployeeRepository </span>which is an in-memory collection of employees. In our upcoming videos we will implement <span style="color: #3d85c6;">SQLRepository </span>which stores and retrieves employees from sql server localdb that we have just configured.
</span>
<br />
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-31976661768370407642020-02-05T12:00:00.000-08:002020-02-05T12:00:08.918-08:00Using sql server in razor pages project - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGw0cRQXw81zjLLc3PkxkfRsp7YX0FWWidSgTWB4vZgwFjK80ZtF_o_EYkfcub_jmFUsBicMBua-_ZY0dZEkD6b_ZNAp11D4Hh6Oqq_O0lRbncPq6HwlOaijduhnL96HR1gNll6-TC6pDX/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGw0cRQXw81zjLLc3PkxkfRsp7YX0FWWidSgTWB4vZgwFjK80ZtF_o_EYkfcub_jmFUsBicMBua-_ZY0dZEkD6b_ZNAp11D4Hh6Oqq_O0lRbncPq6HwlOaijduhnL96HR1gNll6-TC6pDX/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoTgiK2N0ocupaEh6W0-ugbW0sa-nFfTp9nTEWu3oepWC0OEV8hL2JIV3Jj2n6yCeK714KW5ETTp2SngOpAepEe6aROQKQd3bclwEvxf4ZMBEpHbHalkXegSoduNa_yYhIU2r4AKwy8c1o/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoTgiK2N0ocupaEh6W0-ugbW0sa-nFfTp9nTEWu3oepWC0OEV8hL2JIV3Jj2n6yCeK714KW5ETTp2SngOpAepEe6aROQKQd3bclwEvxf4ZMBEpHbHalkXegSoduNa_yYhIU2r4AKwy8c1o/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfeeyhxQcMBuzGxf0DGCscJ7YoeP1xXNmki2BzgDgS1X7PpWmVYFK-K9mpjUX-6uMsrsj3fwCy7zo2NDlqCg4PC_H9NWuRu7VzhQeqGDBSnr23hMoxKrA7yzVhMipoogwp-j0PDPguccBT/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfeeyhxQcMBuzGxf0DGCscJ7YoeP1xXNmki2BzgDgS1X7PpWmVYFK-K9mpjUX-6uMsrsj3fwCy7zo2NDlqCg4PC_H9NWuRu7VzhQeqGDBSnr23hMoxKrA7yzVhMipoogwp-j0PDPguccBT/s320/Slide3.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-7679076801071544612020-02-04T12:14:00.001-08:002020-02-04T12:25:07.741-08:00Install entity framework core in class library project<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/fhO2wRyqNzQ" style="font-family: arial, helvetica, sans-serif;">Part 25 - Pass parameters to view component in asp.net core</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/pass-parameters-to-view-component-in.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/pass-parameters-to-view-component-in_29.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/thRoRKHdtg8">Part 26 - ASP.NET Core view component tag helper</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper_30.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/gb6TMtoGQEM">Part 27 - Implement search page in ASP.NET Core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/02/implement-search-page-in-aspnet-core.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>how to install Entity Framework Core in a separate .NET standard class library project.
</b></span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">So far our application has been working with in memory data. We want to use SQL Server as the database for our application. So let's install entity framework core.
</span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In most real world applications, data access services are usually present in a separate reusable class library project. Install the following 3 nuget packages to install entity framework core.</span>
<br />
<ol style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore.SqlServer</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore.Tools</span></li>
</ol>
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the application that we have been working with so far in this video series, we have a project with name <span style="color: #990000;">RazorPagesTutorial.Services</span>. This is our data access project. So, in the solution explorer, right click on the project name and select <span style="color: #990000;">"Manage NuGet Packages"</span> from the context menu and install the following 3 packages.</span>
<br />
<br />
<table border="1" style="border-collapse: collapse; border: 1px solid black; padding: 3px;">
<tbody>
<tr>
<td><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore
</span></td>
<td><span style="font-family: "arial" , "helvetica" , sans-serif;">As the name implies contains the core entity framework services.
</span></td>
</tr>
<tr>
<td style="white-space: nowrap"><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore.SqlServer
</span></td>
<td><span style="font-family: "arial" , "helvetica" , sans-serif;">Contains the services that lets us use SQL server as the database. This is called the database provider package. If you want to use MySQL as the database instead, then install Pomelo.EntityFrameworkCore.MySql provider package. For each database provider, there is usually a seprate provider specific nuget package which you may have to search for and install.
</span></td>
</tr>
<tr>
<td><span style="font-family: "arial" , "helvetica" , sans-serif;">Microsoft.EntityFrameworkCore.Tools
</span></td>
<td><span style="font-family: "arial" , "helvetica" , sans-serif;">This nuget package contains Package Manager Console tools and commands like Add-Migration, Update-Database etc. We use these commands to create and execute EF Core migrations. We will discuss migrations in our upcoming videos.
</span></td>
</tr>
</tbody></table>
<br />
<span style="color: red; font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>NU1605 detected package downgrade</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">If you get this error, the most likely cause is you have multiple projects in your solution and in one of the projects you just installed a NuGet package. There is already an older version of this same nuget package in one of the other projects in the solution. When you double click on the error, it takes you to the project file that contains the older version of the NuGet package. The obvious fix is to upgrade that NuGet package to the latest version and the error should go away,</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In my case the exact error is the following</span><br />
<span style="color: red; font-family: "arial" , "helvetica" , sans-serif;">NU1605<span style="white-space: pre;"> </span>Detected package downgrade: Microsoft.EntityFrameworkCore from 3.1.1 to 3.0.0. </span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><b>What caused the above error</b></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In one of the projects, I already had <span style="color: #990000;">Microsoft.EntityFrameworkCore</span> 3.0.0 installed. In the same solution, in another project, I just installed <span style="color: #990000;">Microsoft.EntityFrameworkCore</span> 3.1.1 package and then I have the above Detected package downgrade error.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">To fix this I have to upgrade Microsoft.EntityFrameworkCore from 3.0.0 to 3.1.1</span>
<br />
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-5224398640041010942020-02-04T12:14:00.000-08:002020-02-04T12:14:41.343-08:00Install entity framework core in class library project - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCY9SKiMthLYCGLqOcpbAyhcLpIxGKyCGfReFVExMNVxlBKwQHQ9pKjoRxUqXqPM7qiBM-rsVuVLaul2vwwtvj9cW_ZQAPZl8Bhyphenhyphen_gUQCYOv235CbGFF-xM9Lfi7P2UiexpWZ3SBpU0F5R/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCY9SKiMthLYCGLqOcpbAyhcLpIxGKyCGfReFVExMNVxlBKwQHQ9pKjoRxUqXqPM7qiBM-rsVuVLaul2vwwtvj9cW_ZQAPZl8Bhyphenhyphen_gUQCYOv235CbGFF-xM9Lfi7P2UiexpWZ3SBpU0F5R/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYG2Jr_hUt2q5Dsa1AvQBpociICYnCOb4OGkfau8Wc2NVT5zqFd457R08jQBNvsZItend7JOic2V9RBZ95Uk_C8s8qE7cYQDaJw3urZRKUyVhHpZq2BH1vqfPwlNuIjClWE1dsufM4FbwB/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYG2Jr_hUt2q5Dsa1AvQBpociICYnCOb4OGkfau8Wc2NVT5zqFd457R08jQBNvsZItend7JOic2V9RBZ95Uk_C8s8qE7cYQDaJw3urZRKUyVhHpZq2BH1vqfPwlNuIjClWE1dsufM4FbwB/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-46954638264307835132020-02-03T12:41:00.000-08:002020-02-03T12:41:01.130-08:00Implement search page in ASP.NET Core<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Suggested Videos
</span></b><br />
<a href="https://youtu.be/exokw7WQQ-A" style="font-family: arial, helvetica, sans-serif;">Part 24 - ASP.NET Core view components</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-components.html" style="font-family: arial, helvetica, sans-serif;">Text</a><span style="font-family: "arial" , "helvetica" , sans-serif;"> | </span><a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-components-slides.html" style="font-family: arial, helvetica, sans-serif;">Slides</a><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/fhO2wRyqNzQ">Part 25 - Pass parameters to view component in asp.net core</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/pass-parameters-to-view-component-in.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/pass-parameters-to-view-component-in_29.html">Slides</a></span>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><a href="https://youtu.be/thRoRKHdtg8">Part 26 - ASP.NET Core view component tag helper</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper.html">Text</a> | <a href="https://csharp-video-tutorials.blogspot.com/2020/01/aspnet-core-view-component-tag-helper_30.html">Slides</a></span><br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In this video we will discuss <b>how to implement search page in asp.net core
</b></span>
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">We want the search page to look like the following.</span><br />
<br />
<br />
<img alt="asp.net core razor pages search" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2TKPr5b_SyPvpepV99SKCMkmt50llwAf9A16qIiV36yvmo14nrcFuafmtPYC-PU4u4KTp32nGYVNUu2wizfRrnqdFM-1JzCMfjmJmNIvW-8YMLiyIrlO59OzjCJJCzcHYvqx0blZDVvyO/s1600/asp.net+core+razor+pages+search.png" />
<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>How Google search is implemented</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">When we search for something on Google. It issues a <span style="color: blue;">GET </span>request passing the search term in the URL as a query string parameter. The query string parameter name is <span style="color: red;">q</span> (query for short I think). <br /><br />Just like Google, we also want to implement the search using a <span style="color: blue;">GET </span>request so the users can bookmark the URL if they want to. When they click on the book marked URL, they get to the search results straight away without the need to type the search term again.</span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Search Text Box and Button HTML</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">form</span><span style="color: black;"> </span><span style="color: red;">method</span><span style="color: blue;">="get"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="input-group"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">input</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="form-control"</span><span style="color: black;"> </span><b><span style="color: purple;">asp-for</span></b><span style="color: blue;">="</span><span style="color: black;">SearchTerm</span><span style="color: blue;">"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="input-group-append"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">button</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="btn btn-primary"</span><span style="color: black;"> </span><span style="color: red;">type</span><span style="color: blue;">="submit"></span><span style="color: black;">Search</span><span style="color: blue;"></</span><span style="color: maroon;">button</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue; line-height: 107%;"></</span><span style="color: maroon; line-height: 107%;">form</span><span style="color: blue; line-height: 107%;">></span></span></div>
</div>
<ul style="text-align: left;">
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">We are using Bootstrap 4 for styling the <span style="color: blue;">search </span>text box and button.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">On the <span style="color: blue;"><</span><span style="color: #990000;">form</span><span style="color: blue;">></span> element, method attribute is set to <span style="color: blue;">GET</span>, because we want to implement the SEARCH using a GET request.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The <span style="color: blue;"><</span><span style="color: #990000;">input</span><span style="color: blue;">></span> element is bound to <span style="color: blue;">SearchTerm </span>property. We will create this property in the <span style="color: #3d85c6;">PageModel </span>class in just a bit.</span></li>
<li><span style="font-family: "arial" , "helvetica" , sans-serif;">The button type is set to <span style="color: blue;">submit</span>. When this button is clicked the search form is submitted to the server.</span></li>
</ul>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>SearchTerm property in the PageModel class</b></span>
<br />
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">This is the property the <span style="color: blue;"><</span><span style="color: #990000;">input</span><span style="color: blue;">></span> element in the search form is bound to. With [<span style="color: #3d85c6;">BindProperty</span>] attribute in place, ASP.NET Core model binding maps the value typed in the search text box to this property. By default, this happens only on a POST request. We want this model binding to happen on a GET request as well. This is the reason we have set <span style="color: blue;">SupportsGet = true.</span> Since we are using a GET request to implement the search, the search term is passed to the server in the URL as a query string parameter.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">[<span style="color: #3d85c6;">BindProperty</span>(SupportsGet = <span style="color: blue;">true</span>)]</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public string </span>SearchTerm { <span style="color: blue;">get; set;</span> }</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">In the <span style="color: blue;">OnGet()</span> method, call the <span style="color: #3d85c6;">EmployeeRepository </span><span style="color: blue;">Search()</span> method passing it the <span style="color: blue;">SearchTerm</span>.</span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public void </span>OnGet()</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Employees = employeeRepository.Search(SearchTerm);</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>IEmployeeRepository.cs</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public interface </span><span style="color: #3d85c6;">IEmployeeRepository</span></span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">{</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;"> <span style="color: #3d85c6;">IEnumerable</span><<span style="color: #3d85c6;">Employee</span>> Search(string searchTerm);</span><br />
<span style="color: #38761d; font-family: "arial" , "helvetica" , sans-serif;"> // Rest of the code</span><br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">}</span>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>MockEmployeeRepository.cs
</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> </span><span style="color: #2b91af;">MockEmployeeRepository</span><span style="color: black;"> :
</span><span style="color: #3d85c6;">IEmployeeRepository</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">private</span><span style="color: black;"> </span><span style="color: #3d85c6;">List</span><span style="color: black;"><</span><span style="color: #3d85c6;">Employee</span><span style="color: black;">> _employeeList;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: #2b91af;">MockEmployeeRepository</span><span style="color: black;">()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>_employeeList = </span><span style="color: blue;">new</span><span style="color: black;"> </span><span style="color: #3d85c6;">List</span><span style="color: black;"><</span><span style="color: #3d85c6;">Employee</span><span style="color: black;">>()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">new</span><span style="color: black;"> </span><span style="color: #3d85c6;">Employee</span><span style="color: black;">() { Id = 1, Name = </span><span style="color: #a31515;">"Mary"</span><span style="color: black;">, Department = </span><span style="color: #3d85c6;">Dept</span><span style="color: black;">.HR,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>Email = </span><span style="color: #a31515;">"mary@pragimtech.com"</span><span style="color: black;">,
PhotoPath=</span><span style="color: #a31515;">"mary.png"</span><span style="color: black;"> },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">new</span><span style="color: black;"> </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">() { Id = 2, Name = </span><span style="color: #a31515;">"John"</span><span style="color: black;">, Department = </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">.IT,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>Email = </span><span style="color: #a31515;">"john@pragimtech.com"</span><span style="color: black;">,
PhotoPath=</span><span style="color: #a31515;">"john.png"</span><span style="color: black;"> },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">new</span><span style="color: black;"> </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">() { Id = 3, Name = </span><span style="color: #a31515;">"Sara"</span><span style="color: black;">, Department = </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">.IT,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>Email = </span><span style="color: #a31515;">"sara@pragimtech.com"</span><span style="color: black;">,
PhotoPath=</span><span style="color: #a31515;">"sara.png"</span><span style="color: black;"> },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">new</span><span style="color: black;"> </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Employee</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">() { Id = 4, Name = </span><span style="color: #a31515;">"David"</span><span style="color: black;">, Department = </span></span><span style="color: #3d85c6; font-family: "arial" , "helvetica" , sans-serif;">Dept</span><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;">.Payroll,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>Email = </span><span style="color: #a31515;">"david@pragimtech.com"</span><span style="color: black;"> },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>};<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: #3d85c6;">IEnumerable</span><span style="color: black;"><</span><span style="color: #3d85c6;">Employee</span><span style="color: black;">> Search(</span><span style="color: blue;">string</span><span style="color: black;"> searchTerm = </span><span style="color: blue;">null</span><span style="color: black;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">if</span><span style="color: black;"> (</span><span style="color: blue;">string</span><span style="color: black;">.IsNullOrEmpty(searchTerm))<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">return</span><span style="color: black;"> _employeeList;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">return</span><span style="color: black;"> _employeeList.Where(e => e.Name.Contains(searchTerm) ||<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;">
</span>e.Email.Contains(searchTerm)).ToList();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: green;">// Rest of the
code</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: black; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">}</span></span></div>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Index.cshtml - Complete Code
</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background: yellow; color: black;">@page</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background: yellow; color: black;">@model</span><span style="color: black;">
RazorPagesTutorial.Pages.Employees.IndexModel<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background: yellow; color: black;">@{</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>ViewData[</span><span style="color: #a31515;">"Title"</span><span style="color: black;">] = </span><span style="color: #a31515;">"Index"</span><span style="color: black;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>ViewData[</span><span style="color: #a31515;">"ShowButtons"</span><span style="color: black;">] = </span><span style="color: blue;">true</span><span style="color: black;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="background: yellow; color: black;">}</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">style</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: maroon;">.btn</span><span style="color: black;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: red;">width</span><span style="color: black;">: </span><span style="color: blue;">75px</span><span style="color: black;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"></</span><span style="color: maroon;">style</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">vc:head-count</span><span style="color: black;"> </span><span style="color: red;">department</span><span style="color: blue;">="null"></</span><span style="color: maroon;">vc:head-count</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">h1</span><span style="color: blue;">></span><span style="color: black;">Employees</span><span style="color: blue;"></</span><span style="color: maroon;">h1</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">form</span><span style="color: black;"> </span><span style="color: red;">method</span><span style="color: blue;">="get"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="input-group"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">input</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="form-control"</span><span style="color: black;"> </span><b><span style="color: purple;">asp-for</span></b><span style="color: blue;">="</span><span style="color: black;">SearchTerm</span><span style="color: blue;">"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="input-group-append"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><span style="color: maroon;">button</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="btn btn-primary"</span><span style="color: black;"> </span><span style="color: red;">type</span><span style="color: blue;">="submit"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>Search<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"></</span><span style="color: maroon;">button</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"></</span><span style="color: maroon;">form</span><span style="color: blue;">></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: black;"> </span><span style="color: red;">class</span><span style="color: blue;">="card-deck"></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span><span style="background: yellow; mso-highlight: yellow;">@</span></span><span style="color: blue;">foreach</span><span style="color: black;"> (var
employee </span><span style="color: blue;">in</span><span style="color: black;"> Model.Employees)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;"><</span><b><span style="color: purple;">partial</span></b><span style="color: black;"> </span><b><span style="color: purple;">name</span></b><span style="color: blue;">="_DisplayEmployeePartial"</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><b><span style="color: purple;">model</span></b><span style="color: blue;">="</span><span style="color: black;">employee</span><span style="color: blue;">"</span><span style="color: black;"> </span><b><span style="color: purple;">view-data</span></b><span style="color: blue;">="</span><span style="color: black;">ViewData</span><span style="color: blue;">"</span><span style="color: black;"> </span><span style="color: blue;">/></span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue; line-height: 107%;"></</span><span style="color: maroon; line-height: 107%;">div</span><span style="color: blue; line-height: 107%;">></span></span></div>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><b>Index.cshtml.cs - Complete Code
</b></span>
<br />
<br />
<div style="background: silver; padding: 5px;">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">using</span><span style="color: black;"> Microsoft.AspNetCore.Mvc;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">using</span><span style="color: black;"> Microsoft.AspNetCore.Mvc.RazorPages;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">using</span><span style="color: black;"> RazorPagesTutorial.Models;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">using</span><span style="color: black;"> RazorPagesTutorial.Services;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">using</span><span style="color: black;"> System.Collections.Generic;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: blue;">namespace</span><span style="color: black;"> RazorPagesTutorial.Pages.Employees<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> </span><span style="color: #2b91af;">IndexModel</span><span style="color: black;"> : </span><span style="color: #3d85c6;">PageModel</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">private</span><span style="color: black;"> </span><span style="color: blue;">readonly</span><span style="color: black;"> </span><span style="color: #3d85c6;">IEmployeeRepository </span><span style="color: black;">employeeRepository;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: #3d85c6;">IEnumerable</span><span style="color: black;"><</span><span style="color: #3d85c6;">Employee</span><span style="color: black;">> Employees { </span><span style="color: blue;">get</span><span style="color: black;">; </span><span style="color: blue;">set</span><span style="color: black;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span>[</span><span style="color: #3d85c6;">BindProperty</span><span style="color: black;">(SupportsGet = </span><span style="color: blue;">true</span><span style="color: black;">)]<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">string</span><span style="color: black;">
SearchTerm { </span><span style="color: blue;">get</span><span style="color: black;">; </span><span style="color: blue;">set</span><span style="color: black;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: #2b91af;">IndexModel</span><span style="color: black;">(</span><span style="color: #3d85c6;">IEmployeeRepository </span><span style="color: black;">employeeRepository)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">this</span><span style="color: black;">.employeeRepository = employeeRepository;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="color: black;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> OnGet()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>Employees =
employeeRepository.Search(SearchTerm);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: black;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: black; line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif;">}</span></span></div>
</div>
<br />
<a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU">
<img alt="asp.net core tutorial for beginners" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQL0qity03p2X-MyoRtiXkQmEXXf0ObpMBVezf4GRd67LImS1u-qez1Fblab3MdmIUc3H30j5RMEdFxm_Ap7gopEY42C40-nLoUhYakUhROAXdCUqW10x0JiITIqDnJFdDXbo-f7_53o8w/s1600/asp.net+core+tutorial+for+beginners.png" />
</a>
</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-6082652835152798567.post-25529681321364848732020-02-03T12:40:00.000-08:002020-02-03T12:40:55.588-08:00Implement search page in ASP.NET Core - Slides<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqkrIbThQczI3gDMAEfrLomsWeig8f1Db_tdq77hXP8vi37V6moTqHTWVqVAKY88UNn0DMI69C49ZVqC4ZobuV-uQMRD3DuuD-sDijqk7R0a5bBrYRsxMCyJxte0iSt3qF9N9MyzBE8eQO/s1600/Slide1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqkrIbThQczI3gDMAEfrLomsWeig8f1Db_tdq77hXP8vi37V6moTqHTWVqVAKY88UNn0DMI69C49ZVqC4ZobuV-uQMRD3DuuD-sDijqk7R0a5bBrYRsxMCyJxte0iSt3qF9N9MyzBE8eQO/s320/Slide1.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0v14ZCo67gVq6-0TUR2U28Dg-4ScnmnPYu9kEBPHCVqVSvSeYycOqbY5cRC8lpfrxIQPfdAlMp2CBLML-DQ39fD4ZS9Z2XQ_aHgss2meELKKfEcGr9J8TbbNF6rdPEb5U60NFjm3HJhcQ/s1600/Slide2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0v14ZCo67gVq6-0TUR2U28Dg-4ScnmnPYu9kEBPHCVqVSvSeYycOqbY5cRC8lpfrxIQPfdAlMp2CBLML-DQ39fD4ZS9Z2XQ_aHgss2meELKKfEcGr9J8TbbNF6rdPEb5U60NFjm3HJhcQ/s320/Slide2.PNG" width="320" /></a></div>
<hr />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6328538092426311"
data-ad-slot="4600803388"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggcuC7kcmOQHqeTUtICJqg3BSmXqcRYVlYsnL2IVtif1JCpjeaFlVzqCSdSiRbdFRm9R4Yb29HdDujJLAAhRodVf-mIKPKcLqqwgWVejd2dh4zVT2bzEVbzacgAahcgFX-jSmc3qWPyu2C/s1600/Slide3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggcuC7kcmOQHqeTUtICJqg3BSmXqcRYVlYsnL2IVtif1JCpjeaFlVzqCSdSiRbdFRm9R4Yb29HdDujJLAAhRodVf-mIKPKcLqqwgWVejd2dh4zVT2bzEVbzacgAahcgFX-jSmc3qWPyu2C/s320/Slide3.PNG" width="320" /></a></div>
<hr />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn7lAJaaVLiVXm183i94-DYiFPprz7nHmbqm9VYCvf5ib0_Mz8DfgboJsVM2HpE7igKPqrOqxlRZbCYflQrOCd1hQPVTqGX7O9PsbSThb8l7GM6Po8XtAX_7Iux3Mb9gg8AOB7Xp15YbeK/s1600/Slide4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="960" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn7lAJaaVLiVXm183i94-DYiFPprz7nHmbqm9VYCvf5ib0_Mz8DfgboJsVM2HpE7igKPqrOqxlRZbCYflQrOCd1hQPVTqGX7O9PsbSThb8l7GM6Po8XtAX_7Iux3Mb9gg8AOB7Xp15YbeK/s320/Slide4.PNG" width="320" /></a></div>
</div>
Unknownnoreply@blogger.com0