tag:blogger.com,1999:blog-60465779607787877152024-03-13T04:49:07.743-07:00Sanjay Saini's Tech World with Coding Articles for GeeksCoding articles on developing applications using various software development languages, frameworks, tools and technologies such as c#, javascript, asp.net, typescript, python, angular, reactjs and many more.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.comBlogger117125tag:blogger.com,1999:blog-6046577960778787715.post-43118788183783871422019-12-19T08:40:00.000-08:002020-01-07T07:52:57.500-08:00Create CRUD App Using Entity Framework Core with SQL Server<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background: white; margin-bottom: .0001pt; margin: 0cm;">
<span style="color: #171717;"><span style="font-family: "verdana" , sans-serif;">In this article I will be sharing how we can simple CRUD app
using Entity Framework Core edition which is basically an open source and
cross-platform version of the Entity Framework to be used in the .Net Core
application development.<o:p></o:p></span></span></div>
<div style="background: white; margin-bottom: .0001pt; margin: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">With EF Core, data access is performed using a model. A model
is made up of entity classes and a context object (derived from DbContext
class) that represents a session with the database, allowing you to query and save
data in the database.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Here I will be using code first approach without existing database.<span style="font-size: x-small;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="background: white; color: #171717; line-height: 107%;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Prerequisites</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">In order
to develop and run .Net Core app, we need .Net Core SDK that includes .Net CLI
tools, .Net Core Runtime.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "verdana" , sans-serif;">So download and install the latest
version of .Net Core SDK available from this <a href="https://dotnet.microsoft.com/download" target="_blank">link</a>. <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "verdana" , sans-serif;">We will also need code editor, I will
recommend VS Code but if you already have any other code editor that you are
using to write C# code then stick with that otherwise download and install VS
Code from this <a href="https://code.visualstudio.com/download" target="_blank">link</a>. <o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">After installing SDK and VS Code, open
the command prompt and run following command to check if SDK installed
properly.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "courier new" , "courier" , monospace;"><b>dotnet --version</b></span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">You must get the latest version number
as a result. In my case its 3.0.101 since I had installed it sometime back.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">After done with the environment setup
we are ready to develop our CRUD console app.<span style="font-size: x-small;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="background: white; color: #171717; line-height: 107%;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Create a new project</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">Now go to the folder location where
you want to create app project and open the command window. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;">Create console type project for our
CRUD app by running following command.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="font-family: "verdana" , sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>dotnet new console -o EFCore-CrudApp</b></span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">It will create EFCore-CrudApp folder with the same name project
file in it. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Now we need to work under this folder so move into this
folder. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>cd EFCore-CrudApp</b></span><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-size: x-small;"><span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Id5mnwWP3po/XfuZsVq6p_I/AAAAAAAAIFc/7VZHLe6B4909fhKT54YxZOEnXHbqx7w4QCLcBGAsYHQ/s1600/EFCore-CrudApp1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="480" data-original-width="910" height="210" src="https://1.bp.blogspot.com/-Id5mnwWP3po/XfuZsVq6p_I/AAAAAAAAIFc/7VZHLe6B4909fhKT54YxZOEnXHbqx7w4QCLcBGAsYHQ/s400/EFCore-CrudApp1.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-size: x-small;"><span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="background: white; color: #171717; line-height: 107%;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Add Package References</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">First we need to install Entity Framework Core and for that
we need to install the package for the EF Core database provider that we want
to target. In this app we will be using SQL Server so run following command to
install the Entity Framework Core.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>dotnet add package Microsoft.EntityFrameworkCore.SqlServer
--version 3.0.0</b></span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"> Note – I have used
specific versions compatible with .net core SDK 3.0 but if you have latest
version then you should run these command without specifying the version.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">You find following entry in the app project file after
successful installation.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="line-height: 107%;"><span style="font-family: "courier new" , "courier" , monospace;"> <</span></span><span style="font-family: "courier new" , "courier" , monospace;">PackageReference
Include="Microsoft.EntityFrameworkCore.SqlServer"
Version="3.0.0" /></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="line-height: 107%;"><span style="font-family: "courier new" , "courier" , monospace;"> </span></span><span style="color: grey; font-family: "verdana" , sans-serif;"> </span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">As we are done with our app project setup, now open VS code
in the project folder to write code for this app.<span style="font-size: x-small;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="background: white; color: #171717; line-height: 107%;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Create the model</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Our model will consists 2 POCO classes and a context class.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 57.5pt;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Let’s create Model.cs and create following
classes to represent Member and Book entities in our Model.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"> </span><span style="font-family: "courier new" , "courier" , monospace;"> public class Member<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public int Id {
get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public string
Name { get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public string
PhoneNo { get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public string
City { get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public class Book<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public int Id {
get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public string
Title { get; set; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public string
Gener { get; set; } <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Also create CrudAppDbContext class derived from DbContext that
represents session with the database. This class object will be used to perform
crud operations on the database and its properties will represent table in the
database.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">public class CrudAppDbContext: DbContext<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public DbSet<member> Members { get; set; }<o:p></o:p></member></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> public DbSet<book> Books { get; set; }<o:p></o:p></book></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">}</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">We also need to configure the database connection that will
be used by the EF Migrations to sync that database with the data model in the
application.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">So add following code in the CrudAppDbContext class to pass
the database connection while configuring the database context for this app.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">protected override
void OnConfiguring(DbContextOptionsBuilder options)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="background: white; color: #171717;">{ </span><span style="background-color: white; color: #171717; text-indent: 36pt;">options.UseSqlServer(@"Server=localdb)\mssqllocaldb;Database=EFCoreCrudAppDb;Trusted_Connection=True;");</span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">}</span><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Entity
Framework Migrations</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Entity Framework provides a way to create a database from the
data model using Migrations. Migrations are used to keen database in sync with
the changes in the application’s data model by updating the database schema
while preserving existing data in the database.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">So in order to create migrations we need to install Entity
Framework Core tools that includes “dotnet ef” tool and the EF designer.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Run following command in the command window to install the EF
Core tools.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>$ dotnet tool install --global dotnet-ef –version 3.0.0<o:p></o:p></b></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>$ dotnet add package Microsoft.EntityFrameworkCore.Design
–version 3.0.0</b></span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Note – I have used specific versions compatible with .net
core SDK 3.0 but if you have latest version then you should run these command
without specifying the version.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="line-height: 107%;"><span style="font-family: "courier new" , "courier" , monospace;"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="line-height: 107%;"><span style="font-family: "courier new" , "courier" , monospace;"> </span></span><span style="font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">IncludeAssets</span><span style="font-family: "courier new" , "courier" , monospace;">></span><span style="font-family: "courier new" , "courier" , monospace;">runtime; build; native; contentfiles; analyzers; buildtransitive</span><span style="font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">/IncludeAssets</span><span style="font-family: "courier new" , "courier" , monospace;">></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">PrivateAssets</span><span style="font-family: "courier new" , "courier" , monospace;">></span><span style="font-family: "courier new" , "courier" , monospace;">all</span><span style="font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">/PrivateAssets</span><span style="font-family: "courier new" , "courier" , monospace;">></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">/PackageReference</span><span style="font-family: "courier new" , "courier" , monospace;">></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b><span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Create the
database</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Since we have installed Entity Framework Core tools, we are
ready to create database from our application data model.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">First, we need to add migrations that will create the
database schema of our model entities. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">So run following commands to create the database.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">
</span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>dotnet ef migrations add InitialCreate</b></span><span style="font-family: "verdana" , sans-serif; font-size: x-small;"><o:p></o:p></span></span></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-qOJG1vVw5eU/XfuZxL34zVI/AAAAAAAAIFs/KMIWUc0QSeMjHhHOSUzNU6FlNIfD9azGgCEwYBhgL/s1600/EFCore-CrudApp2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="160" data-original-width="520" height="122" src="https://1.bp.blogspot.com/-qOJG1vVw5eU/XfuZxL34zVI/AAAAAAAAIFs/KMIWUc0QSeMjHhHOSUzNU6FlNIfD9azGgCEwYBhgL/s400/EFCore-CrudApp2.png" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Note – It will add Migrations folder in the project with auto-generated
files for “initialCreate” migration.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Second, we need to apply “initialCreate” migration on the
database. Since it’s a very first migration and we don’t have existing database
so it will create new database for us.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">So run following command to apply the migration to the
database.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>dotnet ef database update</b></span><o:p></o:p></span></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-X4SC44Dg-NM/XfuZxGf-T7I/AAAAAAAAIFo/bpn64oyDNv0NLOK7WYisQO1gcTOnHZiWwCEwYBhgL/s1600/EFCore-CrudApp3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="399" data-original-width="520" height="245" src="https://1.bp.blogspot.com/-X4SC44Dg-NM/XfuZxGf-T7I/AAAAAAAAIFo/bpn64oyDNv0NLOK7WYisQO1gcTOnHZiWwCEwYBhgL/s320/EFCore-CrudApp3.png" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Note – A new database is created along with the tables for
the model entities.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="background: white; color: #171717; line-height: 107%;"><span style="font-family: "verdana" , sans-serif;">Add CRUD Operations Code<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Since the database is created, we are ready to add code for
crud operations.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Add new file CrudUtility.cs in the project to add crud
operations code.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Add following code to create (insert) data in the Books table
in database. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">public static
void AddBook()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>using (var
dbcontext = new CrudAppDbContext())<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("**********Enter Book details**********");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("--------------------------------------");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Book Title : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>string
title = Console.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Book Gener : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>string
gener = Console.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine(" ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>var
book = new Book { Title = title, Gener = gener };<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.Books.Add(book);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.SaveChanges();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Add following code to read data from the Books table.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">public static
void GetBooks()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>using (var
dbcontext = new CrudAppDbContext())<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>var
query = from b in dbcontext.Books orderby b.Id select b;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("**********List of Books**********");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("---------------------------------");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>foreach
(var b in query)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("Details of Book No - {0}", b.Id);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("--------------------------------- ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("Book Title - {0}", b.Title);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine("Book Gener -
{0}", b.Gener);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.WriteLine(" ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Add following code to update a particular Book data in the
Books table.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">public static
void UpdateBookDetails(int bookId, string title, string gener)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>using (var
dbcontext = new CrudAppDbContext())<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>var
query = from b in dbcontext.Books orderby b.Id select b;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>foreach
(var b in query)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>if
(b.Id == bookId)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>b.Title = title;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>b.Gener = gener;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.Update(b);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>break;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.SaveChanges();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Add following code to delete a particular Book data from the
Books table.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;">public static
void DeleteBook(int bookId)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>using (var
dbcontext = new CrudAppDbContext())<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>var
query = from b in dbcontext.Books orderby b.Id select b;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>foreach
(var b in query)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>if
(b.Id == bookId)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.Remove(b);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>break;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>dbcontext.SaveChanges();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"> }</span><span style="font-family: "verdana" , sans-serif;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Same way add code to perform CRUD operations on “Member”
entity as well.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">Now we have to call these CRUD operations in our app so add
following code in the Main method of Program.cs file.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"> </span><span style="font-family: "courier new" , "courier" , monospace;">CrudUtility.AddBook();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>CrudUtility.GetBooks();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Enter Book's Id to be deleted : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>int
deletedBookId = int.Parse(Console.ReadLine());<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>CrudUtility.DeleteBook(deletedBookId);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Enter Book's Id to be
updated : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>int
updatedBookId = int.Parse(Console.ReadLine());<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Enter Book's Title : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>string
bookTitle = Console.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>Console.Write("Enter Book's Gener : ");<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>string
bookGener = Console.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="mso-spacerun: yes;"> </span>CrudUtility.UpdateBookDetails(updatedBookId, bookTitle, bookGener);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="font-family: "verdana" , sans-serif;"><span style="background: white; color: #171717;">You can get the complete source code from my GitHub repository
<a href="https://github.com/sanjaysaini2000/EFCore-CrudApp" target="_blank">EFCore-CrudApp</a></span><span style="background: white; color: #171717;"> with the details about how to setup the code on your machine.<span style="font-size: x-small;"><o:p></o:p></span></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<b style="mso-bidi-font-weight: normal;"><span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;"><span style="font-size: large;">Run the App</span><span style="font-size: x-small;"><o:p></o:p></span></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "verdana" , sans-serif;">At last run the app with following command.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="background: white; color: #171717;"><span style="font-family: "courier new" , "courier" , monospace;"><b>Dotnet run</b></span><o:p></o:p></span></div>
</div>
</div>
sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-68351673453231328492019-12-13T09:28:00.000-08:002019-12-13T09:28:12.360-08:00Create Multi Project App in .Net Core 3.0<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
Some time back .Net Core version 3.0 was released and I
thought to explore it and then an idea came to me about creating multi project
application the same way we create in .Net Framework.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
.Net Core is an open source framework for developing and
deploying cross platform application on any platform. Check out this <a href="https://docs.microsoft.com/en-us/dotnet/core/about" target="_blank">link </a>to learn more about .Net Core.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
To demonstrate how we can create, build and deploy multi
project app in the .Net Core 3.0, I have decided to develop a functional CVS
Validator console app. I will explain the functionality of this app later.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
First, we need to setup development environment.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-size: 16.0pt; line-height: 107%;">Prerequisite<o:p></o:p></span><br />
<span style="font-size: 16.0pt; line-height: 107%;"><br /></span>
We basically need .Net CLI tools, .Net Core Runtime and a
code editor in order to develop and run .Net Core app on our machine.</div>
<div class="MsoNormal" style="text-align: justify;">
<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
.Net CLI tools, .Net Core Runtime comes with the .Net Core
SDK so download and install the latest version of .Net Core SDK available from
this <a href="https://dotnet.microsoft.com/download" target="_blank">link</a>.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
And for code editor I will recommend VS Code but if you already
have any other code editor that you are using to write C# code then stick with
that otherwise download and install VS Code from this <a href="https://code.visualstudio.com/download" target="_blank">link </a>.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
After installing SDK and VS Code, open the command prompt
and run following command to check if SDK installed properly.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace;">dotnet --version</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
you must get the latest version number as a result.<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
After done with the environment setup we are ready to develop
our CSV Validator console app.<o:p></o:p><br />
<br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-size: 16.0pt; line-height: 107%;">Create Application
Code Scaffolding <o:p></o:p></span><br />
<span style="font-size: 16.0pt; line-height: 107%;"><br /></span>
This app will have a solution file and three projects to contain
code for client, CSV data validation functionality and unit testing.</div>
<div class="MsoNormal" style="text-align: justify;">
<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<b style="mso-bidi-font-weight: normal;">Create Solution and
Projects<o:p></o:p></b><br />
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal" style="text-align: justify;">
So now go to the folder location where you want to develop
the app and open the command window (since I have GIT installed on my machine,
I will be using git bash window).<o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
Create solution by running following command in the command
window.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace;">dotnet new sln -o CsvValidatorApp</span><o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
It will create CsvValidatorApp folder with the same name
solution file in it. <o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
Now we need to create projects under this folder so move
into this folder. <o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace;">cd CsvValidatorApp</span><o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
First, we will create console type project that will be
startup Client project and entry point of our app. So run following command in
the command window to create it.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Courier New, Courier, monospace;">dotnet new console -o CsvValidator.Client</span><o:p></o:p><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-sdPjZSbacZk/XfPGbsavO3I/AAAAAAAAIEI/7mrzB_ZTXYkD5wAYZe50eNoRmbkq6m8EQCLcBGAsYHQ/s1600/csvvalidator1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="525" data-original-width="941" height="221" src="https://1.bp.blogspot.com/-sdPjZSbacZk/XfPGbsavO3I/AAAAAAAAIEI/7mrzB_ZTXYkD5wAYZe50eNoRmbkq6m8EQCLcBGAsYHQ/s400/csvvalidator1.png" width="400" /></a></div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div style="text-align: justify;">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Second one will be class library type project that will
contain all the functionality for loading, validating and rendering validated
csv file. So run following commands in the command window to create it.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet new classlib -o CsvValidator.Data</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The last one will be the nunit type project for the unit testing
of class library project code that can be created by running following commands
in the command window<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet new nunit -o CsvValidator.Test</span><o:p></o:p></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ukHp5jWczHA/XfPHX_bgL6I/AAAAAAAAIEQ/GqcMTXavQDYFYVHzbxhgI2zmJcPgNXHpACLcBGAsYHQ/s1600/csvvalidator2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="560" data-original-width="895" height="250" src="https://1.bp.blogspot.com/-ukHp5jWczHA/XfPHX_bgL6I/AAAAAAAAIEQ/GqcMTXavQDYFYVHzbxhgI2zmJcPgNXHpACLcBGAsYHQ/s400/csvvalidator2.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Once we are done with the project creation our app code
structure will look like the following image.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fARgSEHBwx8/XfPHr2t_rtI/AAAAAAAAIEY/OIYlLhUumoAXnx9Qbq0fTN54iD1_FShGgCLcBGAsYHQ/s1600/csvvalidator3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="261" data-original-width="705" height="147" src="https://1.bp.blogspot.com/-fARgSEHBwx8/XfPHr2t_rtI/AAAAAAAAIEY/OIYlLhUumoAXnx9Qbq0fTN54iD1_FShGgCLcBGAsYHQ/s400/csvvalidator3.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Add Projects in the Solution<o:p></o:p></b></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal">
Now we need to include the projects into the solution by
running following command in the command window.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet sln CsvValidatorApp.sln add
CsvValidator.Client/CsvValidator.Client.csproj
CsvValidator.Data/CsvValidator.Data.csproj
CsvValidator.Test/CsvValidator.Test.csproj</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-dd9G5hP3z0Y/XfPIM4qryuI/AAAAAAAAIEg/RRlAlHuT59MLeFpLQhtc6DulWe-LpXWXQCLcBGAsYHQ/s1600/csvvalidator4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="285" data-original-width="896" height="125" src="https://1.bp.blogspot.com/-dd9G5hP3z0Y/XfPIM4qryuI/AAAAAAAAIEg/RRlAlHuT59MLeFpLQhtc6DulWe-LpXWXQCLcBGAsYHQ/s400/csvvalidator4.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<b>Add Project Reference</b><br />
<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal">
Now we need to add reference of our class library Data
project in the console app Client project. For that run following command in
the command window.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet add CsvValidator.Client/CsvValidator.Client.csproj reference
CsvValidator.Data/CsvValidator.Data.csproj</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="MsoNormal">
And also add reference of class library Data project in the
Test project by running following command.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet add CsvValidator.Test/CsvValidator.Test.csproj reference
CsvValidator.Data/CsvValidator.Data.csproj</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-bS45tNQw5VE/XfPItSYBG4I/AAAAAAAAIEo/dN2pDMGJ6XEYISfoAqDWDR9myqMvF2_rwCLcBGAsYHQ/s1600/csvvalidator5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="316" data-original-width="920" height="136" src="https://1.bp.blogspot.com/-bS45tNQw5VE/XfPItSYBG4I/AAAAAAAAIEo/dN2pDMGJ6XEYISfoAqDWDR9myqMvF2_rwCLcBGAsYHQ/s400/csvvalidator5.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<b>Build and Run Application</b><br />
<br />
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal">
As we are done with all the scaffolding code creation we are
now ready to build the app for the first time by running following command in
the command window.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet build CsvValidatorApp.sln</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I am sure you won’t get any error since there is not much
code in there.<o:p></o:p></div>
<div class="MsoNormal">
You can run the app by running the console Client project
and get the standard “Hello World” message in the command window. <o:p></o:p></div>
<div class="MsoNormal">
Run following command to run the app.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">dotnet run -p CsvValidator.Client/CsvValidator.Client.csproj</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
or change to CsvValidator.Client folder and run following command.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Courier New, Courier, monospace;">dotnet run</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">Start Building the
App…<o:p></o:p></b></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal">
Now you are ready to put flash into bare bone scaffolding code
of this app and for that we need to open the code editor in the application solution
folder. <o:p></o:p></div>
<div class="MsoNormal">
To open the VS Code in the folder, run following command.<o:p></o:p></div>
<div class="MsoNormal">
code .<o:p></o:p></div>
<div class="MsoNormal">
Get the source code of this app from my GitHub repository from
this <a href="https://github.com/sanjaysaini2000/netcore3-csvvalidator" target="_blank">link </a>and start adding code files and code details in your app.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;">About CVS Validator
App<o:p></o:p></b></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><br /></b></div>
<div class="MsoNormal">
This app take the csv file and validate the data according
to the validation provided to it in an xml file and generate the validated csv
file at the location of the source csv file. Both files path are configured in
the app configuration file. The sample of both files are in my GitHub
repository along with the source code of the app. More details about the app
can be found in the README.md file in the repository as well.<o:p></o:p></div>
<br /></div>
</div>
sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-2663877327901754412019-10-19T10:34:00.000-07:002019-10-19T10:34:40.637-07:00How to deploy Angular app on Firebase?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
I have developed this simple Todo App in Angular which I am going to deploy on Firebase.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-V6PRrctZfSY/XatETDmZBdI/AAAAAAAAH9k/fZi3ISzbIiEkpv695b4Dotjg1Z1spQpWgCLcBGAsYHQ/s1600/img1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="219" data-original-width="527" height="165" src="https://1.bp.blogspot.com/-V6PRrctZfSY/XatETDmZBdI/AAAAAAAAH9k/fZi3ISzbIiEkpv695b4Dotjg1Z1spQpWgCLcBGAsYHQ/s400/img1.jpg" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
You can get the code of this app from my github repository.<o:p></o:p></div>
<div class="MsoNormal">
<a href="https://github.com/sanjaysaini2000/angular-todo-app/tree/firebase">https://github.com/sanjaysaini2000/angular-todo-app/tree/firebase</a><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
First you need to have account on the firebase website so go
to the <a href="https://console.firebase.google.com/">https://console.firebase.google.com</a>
and create your account.<o:p></o:p></div>
<br />
<div class="MsoNormal">
Now create your first firebase project and give it a unique
name. In my case I have named it “angular7-todo-app”.<o:p></o:p></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-hjsJMjAqte8/XatDcizpvYI/AAAAAAAAH9g/jFNufKDi9iMDd9iStvu_dMwE26yXHOwjACEwYBhgL/s1600/firebase1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="715" data-original-width="1132" height="252" src="https://1.bp.blogspot.com/-hjsJMjAqte8/XatDcizpvYI/AAAAAAAAH9g/jFNufKDi9iMDd9iStvu_dMwE26yXHOwjACEwYBhgL/s400/firebase1.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Now install firebase-tools on your machine via npm.<o:p></o:p></div>
<br />
<div class="MsoNormal">
>npm install –g firebase-tools<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-7n9FpAxa3h8/XatEvOS5EsI/AAAAAAAAH94/94hbkuPAgYo_JyIhLz99eufkzpPmgtUrQCLcBGAsYHQ/s1600/firebase2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="468" data-original-width="1026" height="181" src="https://1.bp.blogspot.com/-7n9FpAxa3h8/XatEvOS5EsI/AAAAAAAAH94/94hbkuPAgYo_JyIhLz99eufkzpPmgtUrQCLcBGAsYHQ/s400/firebase2.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Next you need to login to firebase from the console using
following command.<o:p></o:p></div>
<div class="MsoNormal">
>firebase login --interactive<o:p></o:p></div>
<div class="MsoNormal">
This will open the firebase login in the browser for you to
login.<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Mq2LqBjAiSA/XatEv7ENTdI/AAAAAAAAH-A/yPcoIYfOr3YknFBDcE_DoWh6q3egF6w9QCEwYBhgL/s1600/firebase3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="137" src="https://1.bp.blogspot.com/-Mq2LqBjAiSA/XatEv7ENTdI/AAAAAAAAH-A/yPcoIYfOr3YknFBDcE_DoWh6q3egF6w9QCEwYBhgL/s400/firebase3.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Next you need to initialize firebase in the project folder
using following command.<o:p></o:p></div>
<div class="MsoNormal">
>firebase init<o:p></o:p></div>
<br />
<div class="MsoNormal">
This will start a selection wizard in the console.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-LffVfZTTKVc/XatEvv3u5XI/AAAAAAAAH-g/DUtVxPU13FUDmBRzTFN6x0AdGc2SKtBwgCEwYBhgL/s1600/firebase4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="396" data-original-width="757" height="208" src="https://1.bp.blogspot.com/-LffVfZTTKVc/XatEvv3u5XI/AAAAAAAAH-g/DUtVxPU13FUDmBRzTFN6x0AdGc2SKtBwgCEwYBhgL/s400/firebase4.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
First - <span style="mso-spacerun: yes;"> </span>select “Y” to
proceed and then select Hosting option.<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/--EhRGTTJcuU/XatEv0U4cUI/AAAAAAAAH-g/Z0mlQ0h68qYmsV4HZVY5OTAgBtj68F5DgCEwYBhgL/s1600/firebase5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="138" src="https://1.bp.blogspot.com/--EhRGTTJcuU/XatEv0U4cUI/AAAAAAAAH-g/Z0mlQ0h68qYmsV4HZVY5OTAgBtj68F5DgCEwYBhgL/s400/firebase5.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Second – now select existing project option.<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-UVsE1qC6XXY/XatEw13avuI/AAAAAAAAH-c/PFrXbXAoavkr3l8w8m0LLcWYPM1i-pJegCEwYBhgL/s1600/firebase6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="138" src="https://1.bp.blogspot.com/-UVsE1qC6XXY/XatEw13avuI/AAAAAAAAH-c/PFrXbXAoavkr3l8w8m0LLcWYPM1i-pJegCEwYBhgL/s400/firebase6.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
And select the newly created firebase project. <o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fxmF5wktEKQ/XatExBgxhFI/AAAAAAAAH-o/uOnFtEcxdrUSjH0ezYdd3d5vKGoAJaCPACEwYBhgL/s1600/firebase7.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="138" src="https://1.bp.blogspot.com/-fxmF5wktEKQ/XatExBgxhFI/AAAAAAAAH-o/uOnFtEcxdrUSjH0ezYdd3d5vKGoAJaCPACEwYBhgL/s400/firebase7.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Third – Select “No” to configure the app as single page app.
We will configure it by updating firebase.json file.<o:p></o:p></div>
<div class="MsoNormal">
<o:p> </o:p> </div>
<div class="MsoNormal">
Firebase initialization process will create following files
in the project folder.<o:p></o:p></div>
<div class="MsoNormal">
404.html<o:p></o:p></div>
<div class="MsoNormal">
Index.html<o:p></o:p></div>
<div class="MsoNormal">
.firebaserc<o:p></o:p></div>
<div class="MsoNormal">
Firebase.json<o:p></o:p></div>
<div class="MsoNormal">
Note – delete the both html files since we already have index.html
in the project folder.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-iEGQ_dqeTWk/XatExJJQAbI/AAAAAAAAH-k/aVTZJpYIozAsHSw80p9NK-z7E0EXc-0MgCEwYBhgL/s1600/firebase8.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="138" src="https://1.bp.blogspot.com/-iEGQ_dqeTWk/XatExJJQAbI/AAAAAAAAH-k/aVTZJpYIozAsHSw80p9NK-z7E0EXc-0MgCEwYBhgL/s400/firebase8.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Now edit the firebase.json file and add following configuration.<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;">
</span>"public": "docs",<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;">
</span>"rewrites": [<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"> </span>{<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;">
</span>"source": "**",<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;">
</span>"destination": "/index.html"<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"> </span>}<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"> </span>],<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-NAbKumr9SrI/XatExsZImkI/AAAAAAAAH-s/uF1gDT5_tYEwnOI3L34TMvmPzViry0bFgCEwYBhgL/s1600/firebase9.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="712" data-original-width="1270" height="223" src="https://1.bp.blogspot.com/-NAbKumr9SrI/XatExsZImkI/AAAAAAAAH-s/uF1gDT5_tYEwnOI3L34TMvmPzViry0bFgCEwYBhgL/s400/firebase9.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Note – make sure the outputPath value in the angular.json
should be “docs”.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-TbjHRUYTU2w/XatHwkEtg2I/AAAAAAAAH-0/iaaxTTWGizkb3LWgVX9v4x_KcXwhc686QCLcBGAsYHQ/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" height="216" src="https://1.bp.blogspot.com/-TbjHRUYTU2w/XatHwkEtg2I/AAAAAAAAH-0/iaaxTTWGizkb3LWgVX9v4x_KcXwhc686QCLcBGAsYHQ/s400/img6.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Now run following commad on the console window to generate
distributable files in the docs folder.<o:p></o:p></div>
<div class="MsoNormal">
ng build - -prod <o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-2XWxtNzIXuI/XatEuD04ZAI/AAAAAAAAH-g/pcjwQlpXNcw9FaHvcXq_2ALrDv2vNvO_gCEwYBhgL/s1600/firebase10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="363" data-original-width="831" height="174" src="https://1.bp.blogspot.com/-2XWxtNzIXuI/XatEuD04ZAI/AAAAAAAAH-g/pcjwQlpXNcw9FaHvcXq_2ALrDv2vNvO_gCEwYBhgL/s400/firebase10.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Finally deploy the app using following command.<o:p></o:p></div>
<div class="MsoNormal">
>firebase deploy<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-V-n4mx_o8Ns/XatEuAbEjTI/AAAAAAAAH-Y/bvqOtHh_WwkXAQiij7RrbWFIalY63Cb7wCEwYBhgL/s1600/firebase11.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="402" data-original-width="1157" height="138" src="https://1.bp.blogspot.com/-V-n4mx_o8Ns/XatEuAbEjTI/AAAAAAAAH-Y/bvqOtHh_WwkXAQiij7RrbWFIalY63Cb7wCEwYBhgL/s400/firebase11.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal">
Now open the hosting URL <a href="https://angular7-todo-app.firebaseapp.com/">https://angular7-todo-app.firebaseapp.com</a>
in the browser.<o:p></o:p></div>
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-hW1afF3QLV4/XatEuPVbT8I/AAAAAAAAH-Y/tO-qjTduUOEZUXwLc6PdNwsSJoIAqUTJACEwYBhgL/s1600/firebase12.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="460" data-original-width="1496" height="122" src="https://1.bp.blogspot.com/-hW1afF3QLV4/XatEuPVbT8I/AAAAAAAAH-Y/tO-qjTduUOEZUXwLc6PdNwsSJoIAqUTJACEwYBhgL/s400/firebase12.png" width="400" /></a></div>
<br /></div>
sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-64469877617447422152019-09-13T00:50:00.000-07:002019-09-14T07:55:24.487-07:00How to deploy Angular app on GitHub Pages?<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
I have developed this simple Todo App in Angular which I am
going to deploy on GitHub Pages.<o:p></o:p></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-eplUG2BICF0/XXqCAmvVB3I/AAAAAAAAH5A/Ue4_vuw5il8WTn82ffxxn9E4NcXxvN4cQCEwYBhgL/s1600/img1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="219" data-original-width="527" src="https://1.bp.blogspot.com/-eplUG2BICF0/XXqCAmvVB3I/AAAAAAAAH5A/Ue4_vuw5il8WTn82ffxxn9E4NcXxvN4cQCEwYBhgL/s1600/img1.jpg" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
First you need to put your local code into the github.com so
if you don’t have github account you need to create it first.<br />
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
Now create github repository in which you will upload your
local code.<o:p></o:p><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-dpTZMfDUzIY/XXsjalVYrxI/AAAAAAAAH5U/bz1IkXaM0hs89lwD5SXmOKW-mZ6Q6wO9gCLcBGAsYHQ/s1600/img2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="237" data-original-width="527" src="https://1.bp.blogspot.com/-dpTZMfDUzIY/XXsjalVYrxI/AAAAAAAAH5U/bz1IkXaM0hs89lwD5SXmOKW-mZ6Q6wO9gCLcBGAsYHQ/s1600/img2.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="MsoNormal">
Assuming you have git installed on your machine and you have
already committed your code in the local master branch.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-VU6-7B7YArk/XXsjaiLf38I/AAAAAAAAH5c/whhvCE-4aOwUxK-zTSggfLT0dhopttK8gCEwYBhgL/s1600/img3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="219" data-original-width="527" src="https://1.bp.blogspot.com/-VU6-7B7YArk/XXsjaiLf38I/AAAAAAAAH5c/whhvCE-4aOwUxK-zTSggfLT0dhopttK8gCEwYBhgL/s1600/img3.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
<br /></div>
</div>
<br />
<div class="MsoNormal">
Open the git bash on the app folder and run above commands
to upload your code on github.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-8ChxFpgmm1w/XXsqPDUtUnI/AAAAAAAAH5s/-wrUSeW-JDQyPDTfyrfvn8LR-Dn31LNEQCLcBGAsYHQ/s1600/img4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="384" data-original-width="886" height="172" src="https://1.bp.blogspot.com/-8ChxFpgmm1w/XXsqPDUtUnI/AAAAAAAAH5s/-wrUSeW-JDQyPDTfyrfvn8LR-Dn31LNEQCLcBGAsYHQ/s400/img4.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="MsoNormal">
Now refresh your github repository and check your code is
pushed into github.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6ZpRy9XJKNE/XXsjbfkbe-I/AAAAAAAAH5k/1U9ly-E-5Kw6qDlAz4h-I_dRj56tHBa8ACEwYBhgL/s1600/img5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="384" data-original-width="793" height="193" src="https://1.bp.blogspot.com/-6ZpRy9XJKNE/XXsjbfkbe-I/AAAAAAAAH5k/1U9ly-E-5Kw6qDlAz4h-I_dRj56tHBa8ACEwYBhgL/s400/img5.png" width="400" /></a><a href="https://1.bp.blogspot.com/-6ZpRy9XJKNE/XXsjbfkbe-I/AAAAAAAAH5k/1U9ly-E-5Kw6qDlAz4h-I_dRj56tHBa8ACEwYBhgL/s1600/img5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we need to build our code in production mode in order to
create distributable files that will be deployed on github pages. By default
this deployable code generated in the /dist/prodect-name folder but we
need to generate this in the “docs” folder under the app folder.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-6ZpRy9XJKNE/XXsjbfkbe-I/AAAAAAAAH5k/1U9ly-E-5Kw6qDlAz4h-I_dRj56tHBa8ACEwYBhgL/s1600/img5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
</a></div>
<div class="MsoNormal">
So we need to make a small change in the angular.json file
and change the outputpath value to “docs/” as shown below and save the changes.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" src="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" /></a></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Another point to be noted is the URL of your going to be
hosted app on the github pages.<o:p></o:p></div>
<div class="MsoNormal">
This default site name on the github pages would be
https://username.github.io/respositoryname<o:p></o:p></div>
<div class="MsoNormal">
Now run following comman on the git bash window to generate
distributable files in the docs folder.<o:p></o:p></div>
<div class="MsoNormal">
ng build - -prod - -base-href=” <a href="https://username.github.io/respository-name/">https://username.github.io/respository-name/</a>”<o:p></o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
Note – replace the username and repository-name with your github
username and repository.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-xeJM4RAXE_k/XXsxMAsLGaI/AAAAAAAAH6c/BAOP1CZRTQw09Bi_7SM-7QHnKBlE2zcKACEwYBhgL/s1600/img7.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" src="https://1.bp.blogspot.com/-xeJM4RAXE_k/XXsxMAsLGaI/AAAAAAAAH6c/BAOP1CZRTQw09Bi_7SM-7QHnKBlE2zcKACEwYBhgL/s1600/img7.png" /></a></div>
<br />
<br />
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Go to your app folder and check docs folder is created that
contains all the distributable files.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-bznq0ro8htA/XXsxMwpUvEI/AAAAAAAAH6c/-KITOa1VGh0afoHVUH5Odd0Jw0EGTSL9gCEwYBhgL/s1600/img8.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" src="https://1.bp.blogspot.com/-bznq0ro8htA/XXsxMwpUvEI/AAAAAAAAH6c/-KITOa1VGh0afoHVUH5Odd0Jw0EGTSL9gCEwYBhgL/s1600/img8.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now commit this folder into local repository and also push
it into the github.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-FrXBtQ7igNc/XXsxMze4f4I/AAAAAAAAH6Y/-dAnDm06KjQkqLAJFGQKjrb5FvSU_6uDwCEwYBhgL/s1600/img9.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="308" data-original-width="551" src="https://1.bp.blogspot.com/-FrXBtQ7igNc/XXsxMze4f4I/AAAAAAAAH6Y/-dAnDm06KjQkqLAJFGQKjrb5FvSU_6uDwCEwYBhgL/s1600/img9.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Once docs folder is pushed into you github repository you
need to open the repository settings and go to the Github Pages section and
select “master branch/docs folder” from Source dropdown.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-pcCeWTyYBWA/XXsxL_c3nvI/AAAAAAAAH6U/dl_nxrs0_moJgTN9LOWqbCx8_1_q5gMJwCEwYBhgL/s1600/img10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" src="https://1.bp.blogspot.com/-pcCeWTyYBWA/XXsxL_c3nvI/AAAAAAAAH6U/dl_nxrs0_moJgTN9LOWqbCx8_1_q5gMJwCEwYBhgL/s1600/img10.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now open the github page url of your deployed app in the
browser window to check successful deployment of your app on the github pages.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-Pwz4jRdLs4g/XXsxLs0IIJI/AAAAAAAAH6U/GXavIqHWtJUvAswVPeHo11l28o8wio8bgCEwYBhgL/s1600/img11.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="551" src="https://1.bp.blogspot.com/-Pwz4jRdLs4g/XXsxLs0IIJI/AAAAAAAAH6U/GXavIqHWtJUvAswVPeHo11l28o8wio8bgCEwYBhgL/s1600/img11.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br />
Here is the URL of this app - <a href="https://sanjaysaini2000.github.io/angular-todo-app/" target="_blank">https://sanjaysaini2000.github.io/angular-todo-app/</a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
There is another
method to deploy you Angular app only on github pages using angular-cli-ghpages
package that you can google for more details but personally I find this
approach better and clear than using that packages.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH6Q/D6CkD52bH4QA1vgbn-QtwUzPQniNa5Z-ACEwYBhgL/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH58/q2K32-OiURAdilbgCzVYLRt16w4x0TyIgCLcBGAsYHQ/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH58/q2K32-OiURAdilbgCzVYLRt16w4x0TyIgCLcBGAsYHQ/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://1.bp.blogspot.com/-zizaeURy9y4/XXsxL-sQIzI/AAAAAAAAH58/q2K32-OiURAdilbgCzVYLRt16w4x0TyIgCLcBGAsYHQ/s1600/img6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-73711879721426364542015-06-13T21:04:00.000-07:002015-06-13T21:04:37.756-07:00How to remove istartsurf.com from the system or protectservice.exe<div dir="ltr" style="text-align: left;" trbidi="on">
iStartSurf is a browser hijacker. iStartSurf it’s technically not a virus, but it does exhibit plenty of malicious traits. It gets installed on your computer after you have installed a freeware software that had bundled into their installation this browser hijacker. To remove this browser hijacker you will need to remove protectservice.exe from your machine.<br />
<br />
How to Remove Protectservice.exe Virus<br />
<br />
Steps:<br />
<br />
1. Open windows explorer and go to the C:\Program Files\XTab folder. On 64bit machines go to C:\Program Files(x86)\XTab<br />
<br />
2. You will find uninstall exe, run it to uninstall the protectservice.exe from your machine.<br />
<br />
3. After successful uninstall, reset all the browsers (e.g. chrome, ie, firefox). In the IE the option is in the Internet Options->Advance tab. Google for other browser if not sure how to reset.<br />
<br />
4. Now restart your machine.</div>
sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-42080849303746958252010-12-11T22:11:00.001-08:002010-12-11T22:11:49.437-08:00How to get Comma Separated Values (CSV) from Table ColumnThis is another very common requirement while developing sql code for the applications. <br />And again this can be done in various ways...one of them is here...<br /><br />Example:<br /><br />create table user_reports<br />(id int identity, username varchar(20),report_name varchar(20), report_available bit)<br />go<br />insert into user_reports(username,report_name,report_available)<br />select 'Ajay', 'report1',1<br />union all<br />select 'Ajay', 'report2',1<br />union all<br />select 'Ajay', 'report3',1<br />union all<br />select 'Ajay', 'report4',1<br />union all<br />select 'John', 'report5',0<br />union all<br />select 'John', 'report6',1<br />union all<br />select 'John', 'report2',0<br />union all<br />select 'Tony', 'report1',1<br />union all<br />select 'Tony', 'report7',1<br />union all<br />select 'Ram', 'report3',1<br />union all<br />select 'Ram', 'report4',0<br />union all<br />select 'Ram', 'report8',1<br /><br /><br />-- CSV report list for all users<br />select stuff(<br />(select ',' + ur.report_name<br />from user_reports ur<br />order by ur.report_name<br />for xml path('')),1,1,'') as 'Report List'<br />go<br /><br />-- CSV report list for a given user<br />select stuff(<br />(select ',' + ur.report_name<br />from user_reports ur where username = 'Ajay'<br />order by ur.report_name<br />for xml path('')),1,1,'') as 'Report List'<br />go<br /><br />-- CSV report list user wise<br />select ur1.username,stuff(<br />(select ',' + ur.report_name<br />from user_reports ur where ur.username=ur1.username<br />order by ur.report_name<br />for xml path('')),1,1,'') as 'Report List'<br />from user_reports ur1 group by ur1.username<br />gosanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-1629139291956736492010-12-11T21:16:00.000-08:002010-12-11T21:17:08.975-08:00How to aggregate BIT Columns with Group By in SQL ServerThis is a very common requirement in sql when you are deveploping applications.<br />You can achive this with very simple query, using cast and min sql functions.<br /><br />Example:<br /><br />create table user_reports<br />(id int identity, username varchar(20),report_name varchar(20), report_available bit)<br />go<br />insert into user_reports(username,report_name,report_available)<br />select 'Ajay', 'report1',1<br />union all<br />select 'Ajay', 'report2',1<br />union all<br />select 'Ajay', 'report3',1<br />union all<br />select 'Ajay', 'report4',1<br />union all<br />select 'John', 'report5',0<br />union all<br />select 'John', 'report6',1<br />union all<br />select 'John', 'report2',0<br />union all<br />select 'Tony', 'report1',1<br />union all<br />select 'Tony', 'report7',1<br />union all<br />select 'Ram', 'report3',1<br />union all<br />select 'Ram', 'report4',0<br />union all<br />select 'Ram', 'report8',1<br /><br /><br />-- This simple sql query will return user wise aggregated report_available column value <br />select username as UserName, cast(min(cast(report_available as int)) as bit) as 'Is Report Available'<br />from user_reports group by usernamesanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-19397258140660212012010-12-11T06:44:00.000-08:002010-12-11T06:46:39.254-08:00SSIS Error : Failed to save package file, Element not found.There could be many reasons that can cause this error but in my case the reason was that MSXML6.dll was not registered on my machine. So I just registered this dll to resolve this error.<br /><br />To register MSXML6.dll on your machine, follow these steps:<br />1. From the Start menu, click Run. <br />2. Enter the following command: regsvr32 %windir%\system32\msxml6.dll. <br />3. Click OK.<br /><br />Note - Replace %windir% with the path of windows folder on your machine. I my case it was - c:\windowssanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-10828293543863418352010-06-02T21:38:00.000-07:002010-06-02T21:53:01.021-07:00How to handle errors in APS.NETThere are three ways to handle errors in asp.net application.<br /><br /><strong>1. Using Page class Error even:</strong><br /><br />You can handle error on every page by define error handler for Page class Error event.<br />Like-<br /><br /> void Page_Error(object sender, EventArgs e)<br /> {<br /> Response.Redirect("Errorpage.htm");<br /> }<br /><br /><strong>2. By defining error handler in global.asax file</strong><br /><br />This is better approach than the first one because its a centralize approach to handle errors. Here instead of writing error handler in every web page, you will need to define error handler at application level in the global.asax file. <br />Like:<br /><br /> void Application_Error(object sender, EventArgs e) <br /> {<br /> Response.Redirect("Errorpage.htm");<br /> }<br /><br /><strong>Note:-</strong> Whenever an error occurs application look for error handler at page level and then at application level. So if you have defined error handler in the web pages then it will handle the error not the one defined in global.asax file.<br /><br /><strong>3. By adding customError tag in the web.config file</strong><br /><br />This is another centralize approach to error handling in ASP.NET. In fact you can redirect to different custom error pages for different error status codes.<br />Like:<br /><br /> < customErrors defaultRedirect="error.htm" mode="On" ><br /> < error statusCode="404" redirect="notfound.htm"/ ><br /> < /customErrors >sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com2tag:blogger.com,1999:blog-6046577960778787715.post-37977825726733077492010-05-17T00:49:00.000-07:002010-05-17T00:50:57.465-07:00Error: possible soap version mismatchSometime you may encounter below mentioned error when you try to access web service in your .net application. <br /><br /><blockquote>Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.</blockquote><br /><br />Actually if you are setting URL property in your .net application with wrong web service url than most likely you may get this error. The general mistake is that people assign same url which they used to see the description of web service (e.g. http://localhost/servlet/webservices?ver=1.1?wsdl) to the URL property of the proxy class instead of the web service url(e.g. http://localhost/servlet/webservices?ver=1.1). So assign the web service url and see if you are able to resolve this error.<br />If still you are not able to resolve this error then make sure the url you are assigning is correct.<br /><br />Note: - I have noticed that in case web service is developed in .Net and is consumed by a .Net client then assigning description url (e.g. http://localhost/webservices/service.asmx?wsdl) does not generate this error. But if the web service is developed with non .net technology and generates WSDL that is somewhat different from what .Net clients expect then this error will most likely come up in that case try above given solution.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-90472514181566102862010-05-11T21:14:00.000-07:002010-05-11T21:36:52.056-07:00Error: A semi colon character was expected. Error processing resourceVery often people encounter this error when they try to open xml file in IE or try to load it in their code. The most common reason for this error is that your xml file may be containing "&" character. Actually IE misunderstands "&" character with some HTML code that starts with "&" and ends with ";" character like-& nbsp ; means non-breaking space and rendered as a white space.<br /><br />For Example: here is the content of an xml file which will give this error due to "&" character in the url.<br /><br />< ?xml version="1.0" encoding="utf-8" ? ><br /><><br /><><br />< name="WSACCPURL"><br /><>http://localhost/Test/webservices?ver=1.1&wsdlxml< /value ><br />< /setting ><br />< /appSettings ><br />< /configuration ><br /><br />So to resolve this error I replaced the "&" character with HTML code phrase "& amp ;"<br />Note:- Ignore the space between & and ; there should not be any space. Here I had to give space to avoid their special meaning by IE.<br /><br />Now the updated xml file is:<br /><br />< ?xml version="1.0" encoding="utf-8" ? ><br /><><br /><><br />< name="WSACCPURL"><br /><>http://localhost/Test/webservices?ver=1.1& amp ;wsdlxml< /value ><br />< /setting ><br />< /appSettings ><br />< /configuration ><br /><br /><br />Now when this file is opened in IE the & amp ; is rendered as & character.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com4tag:blogger.com,1999:blog-6046577960778787715.post-24590332166010097972010-05-06T21:31:00.000-07:002010-05-06T21:36:12.462-07:00Consuming web service in classic ASP application using .Net componentIt’s fairly simple to consume web service in your classic ASP application using wrapper component developed in .net world.<br /><br />So first create a wrapper component that will consume the web service.<br />Follow below given steps:<br /><br />1. Open visual studio and create a Class Library project in C#.<br />2. Name the project WebServiceWrapper and the class as Wrapper.<br />3. Paste below code in the Wrapper.cs class window.<br /><br />-----------------------------------------<br />using System;<br /><br />namespace WebServiceWrapper<br />{<br /><br />public class Wrapper<br />{<br /><br />MyWebService.Service1 svr;<br /><br />public Wrapper()<br />{<br />}<br /><br />public void Initialize(String url)<br />{<br />svr=new WebServiceWrapper.MyWebService.Service1();<br />svr.Url=url;<br />}<br /><br />public String URL<br />{<br />get{return svr.Url;}<br />set{svr.Url=value;}<br />}<br /><br />public String HelloWorld(String str)<br />{<br />return svr.HelloWorld(str);<br />}<br /><br />public String HelloWorld(String str, String url)<br />{<br />svr=new WebServiceWrapper.MyWebService.Service1();<br />svr.Url=url;<br />return svr.HelloWorld(str);<br />}<br /><br />}<br />}<br />-----------------------------------------<br /><br />4. Right click on the project and choose Add Web Reference option.<br />5. In the Add Web Reference window browse your web service and give the web reference name: MyWebService and click on Add Reference button. <br /><br /><strong>Note:-</strong> In the above code web service in question(Service1) is hosted on local machine and has a method named HelloWorld that takes string param and return string value but you have to replace this code with your web service name and web method accordingly.<br /><br />6. Build the solution that will create WebServiceWrapper.dll<br />7. Now you have to create type library of your .net component and register that to make it available in your VB COM component. For that use following command at VS .Net command prompt window.<br /><br /><em>regasm.exe < path of WebServiceWrapper.dll > /tlb /codebase</em><br /><br />It will create a type library named WebServiceWrapper.tlb at the dll location and register the same as well. Ignore any warning message shown.<br /><br />You are done with creating your .NET wrapper component. Now time to use it in your VB COM component.<br />Here I assume that you would have gone through my previous post <a href='http://sanjaysainitech.blogspot.com/2010/05/how-to-create-asp-application-using-asp.html'>"How to create ASP application using ASP Object Library"</a> becasue here I will tell you what changes are needed to do in your ASPComp component that you would have created earlier.<br /><br />So Open your ASPComp project and add following code in the clsASP class.<br />-----------------------------------------<br />Public Sub CallWrapper_HelloWorld()<br /> <br />Dim oclient<br />Dim strg As String<br />On Error GoTo ErrorHandler<br />Set oclient = CreateObject("WebServiceWrapper.Wrapper")<br />oclient.Initialize "http://localhost/WebService1/Service1.asmx?wsdl"<br /><br />strg = oclient.HelloWorld("Sanjay")<br />oResponse.Write strg & vbCrLf<br /><br />Exit Sub<br /><br />ErrorHandler:<br /><br />oResponse.Write "Invalid Web Service Request. Please check the Web Service URL: " & Err.Description<br /><br />End Sub <br />----------------------------------------<br /><strong>Note:-</strong> Replace the web service url with your web servce url.<br /><br />Now go to Project-> reference menu and add reference of WebServiceWrapper Type Library that you had created earlier by browsing to its location.<br /><br />Now re-make ASPComp.dll to incorporate new changes in the COM component.<br /><br /><strong>Note:-</strong> You will have to re-register the ASPComp.dll<br /><br />After completing the COM component changes, open your asp page in the notepad and replace the method call with the newly created method.<br /><br />So your MyASP.asp page will look like:<br /><br />< %<br />Set oExample = Server.CreateObject("ASPComp.clsASP")<br />oExample.CallWrapper_HelloWorld<br />% ><br /><br />No time to test user efforts. So browse http://localhost/ASPTest/MyASP.asp in the IE window.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-43087098650558038662010-05-05T21:10:00.000-07:002010-05-05T21:17:07.164-07:00How to consume web service in classic ASP application using Soap 3.0It's fairly simple to consume web service using Microsoft Soap Type Library 3.0 in your classic ASP application.<br />Here I assume that you would have gone through my previous post <a href='http://sanjaysainitech.blogspot.com/2010/05/how-to-create-asp-application-using-asp.html'>"How to create ASP application using ASP Object Library"</a> becasue here I will tell you what changes are needed to do in your ASPComp component that you would have created earlier.<br /><br />So Open your ASPComp project and add following code in the clsASP class.<br />-------------------------------------<br />Public Sub Call_HelloWorld()<br /> <br />Dim oclient<br />Dim strg As String<br />On Error GoTo ErrorHandler<br />Set oclient = CreateObject("MSSOAP.SoapClient30")<br />oclient.MSSoapInit "http://localhost/WebService1/Service1.asmx?wsdl"<br /><br />strg = oclient.HelloWorld("Sanjay")<br />oResponse.Write strg & vbCrLf<br /><br />Exit Sub<br /><br />ErrorHandler:<br /><br />oResponse.Write "Invalid Web Service Request. Please check the Web Service URL: " & Err.Description<br /><br />End Sub <br />--------------------------------------<br /><strong>Note:-</strong> In the above code web service in question is hosted on local machine and has a method named HelloWorld that takes string param and return string value but you have to replace this code with your web service and web method.<br /><br />Now go to Project-> reference menu and add reference of Microsoft Soap Type Library 3.0<br /><br />Generally it is installed with Office 2003 but if its not installed on your machine then you can download it from <a href='http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displayLang=en&oRef=http%3a%2f%2fwww.microsoft.com%2fdownloads%2fthankyou.aspx%3ffamilyId%3dC943C0DD-CEEC-4088-9753-86F052EC8450%26displayLang%3den%26oRef%3dhttp%253a%252f%252fwww.google.com%252fsearch%253fq%253dSoap%252b3.0%252bdownload%2526btnG%253dSearch%2526hl%253den%2526lr%253d%2526rls%253dRNWE%25252CRNWE%25253A2005-12%25252CRNWE%25253Aen'>here</a> and install it on your machine.<br /><br />Now you will have to re-make ASPComp.dll<br /><br /><strong>Note:-</strong> You will have to re-register the ASPComp.dll<br /><br />After completing the component changes, open your asp page in the notepad and replace the method call with the newly created method.<br /><br />So your MyASP.asp page will look like:<br /><br />< %<br />Set oExample = Server.CreateObject("ASPComp.clsASP")<br />oExample.Call_HelloWorld<br />% ><br /><br />You are done with the changes. So browse http://localhost/ASPTest/MyASP.asp in the IE window.<br /><br />Reference: http://www.aspfree.com/c/a/VB.NET/Calling-a-Web-Service-using-VB6-with-SOAP-30/1/sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-35241071523256811762010-05-05T20:55:00.000-07:002010-05-05T21:19:03.265-07:00How to create ASP application using ASP Object LibraryMicrosoft ASP Object Library provides five ASP Intrinsic Objects i.e. Request, Response, Server, Session, and Application that can be used in the COM component to develop re-usable code components that can be used in other ASP applications.<br /><br />Here I am going to show you how you can create ASP application that uses COM component developed in VB that is using ASP object library.<br /><br />Below are the steps to create very-very simple ASP application.<br /><br />1. Open the MS Visual Basic 6.0 and create ActiveX DLL project.<br />2. Rename the project1 as ASPComp and class1 as clsASP.<br />3. Copy below code in the clsASP class window.<br /><br />Private oContext As ObjectContext<br />Private oResponse As Response<br /><br />Implements ObjectControl<br /><br />Private Sub ObjectControl_Activate()<br /> Set oContext = GetObjectContext()<br /> Set oResponse = oContext("Response")<br />End Sub<br /><br />Private Sub ObjectControl_Deactivate()<br /> Set oContext = Nothing<br /> Set oResponse = Nothing<br />End Sub<br /><br />Private Function ObjectControl_CanBePooled() As Boolean<br /> ObjectControl_CanBePooled = False<br />End Function<br /><br />Public Sub HelloWorld()<br /> oResponse.Write "Hello World!<BR>" & vbCrLf<br />End Sub<br /><br />4. Now open project-> references window from menu and add reference of following items.<br /> <em>Microsoft Active Server Pages Object Library.<br /> COM+ 1.0 Admin Type Library<br /> COM+ Services Type Library</em><br /><br />5. Now go to file menu and make the ASPComp.dll<br /><br />You are done with creating COM component and now you have to create an ASP page that will comsume this component.<br /><br />So create a folder named ASPTest in the in wwwroot folder and then create an asp page named MyASP.asp in it.<br /><br />Open this page in notepad and copy following code in it and save it.<br /><br />< %<br />Set oExample = Server.CreateObject("ASPComp.clsASP")<br />oExample.HelloWorld<br />% ><br /><br />Now one last thing to be done is to register the component in the COM+ services. You can do it by setting the class's MTSTransactionMode property = 1 - NoTransaction or through steps given below:<br /><br />1. Open the Component Services Window and right click on the COM+ Applications<br />2. From the context menu select new->application<br />3. A Wizard will open, click on next button.<br />4. Choose Create Empty application and enter the application name - ASPComp, leave other settings as is and click on next button.<br />5. Again leave the settings as is and click on next button.<br />6. Click on Finish button.<br />7. Now you can see ASPComp in the list of COM+ Applications. Double click on it.<br />8. Now right click on component and choose new->component<br />9. A wizard will open, click on the next button.<br />10. Choose the install new component and browse and select the ASPComp.dll and click on open button.<br />11. Click on Finish button.<br />12. Now right click on ASPComp and click on start option.<br /><br />You are done with the development now time to test it.<br /><br />Open the IE and type following address in the address bar.<br /><br />http://localhost/ASPTest/MyASP.asp<br /><br />You should see - "Hello World" on the page.<br /><br /><br />Reference: http://www.stardeveloper.com/articles/display.html?article=2000041401&page=1sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-49084202289337862402010-03-07T09:26:00.000-08:002010-03-07T09:32:58.643-08:00ASP.NET Coding Model- Inline Code, Code-Behind & Code-Beside<strong>Inline Code:</strong><br />It’s an old style of coding model, where your business logic code appears in <br />< script runat=”server”> < /script > block in the .aspx page itself.<br /><br /><strong>Example:</strong><br /><br />< %@ Page Language=”C#” % ><br />< script runat=”server”><br />void Page_Load(object sender, eventArgs e)<br />{<br />Label1.Text=”Hello World”;<br />}<br />< /script><br />< html ><br />< body ><br />< form id=”form1” runat=”server” ><br />< asp:Label ID=”Label1” Runat=”server” / ><br />< /form ><br />< /body ><br />< /html ><br /><br />When first time this page loads,it is compiled into a class that resides in an assembly stored in a subfolder of the “C:\WINDOWS\Microsoft.NET\Framework\v2.x.xxxx\Temporary AST.NET files” folder. This compiled version of the page is good until the .aspx file changes or the application is restarted, at that time it will have to be recompiled.<br /><strong>Note-</strong> By default web page inherits from the System.Web.UI.Page class, so if you want your page inherits from some other class (which in turn must inherit from Page class), add “inherits” attribute to the Page directive.<br /><br /><strong>Code-Behind: Non-Compiled</strong><br /><br />This coding style was used by the people, who wanted to change code on-the-fly without having to build their projects, or who wanted to separate code from HTML but didn’t have Visual Studio tool.<br /><br /><strong>Example:</strong><br /><br />default.aspx file:<br /><br />< %@ Page Language=”C#” Src=”default.aspx.cs” Inherits=”CodeBehindClass” % ><br />< html ><br />< body ><br />< form id=”form1” runat=”server” ><br />< asp:Label ID=”Label1” Runat=”server” / ><br />< /form ><br />< /body ><br />< /html ><br /><br />Default.aspx.cs file:<br /><br />using System;<br />using System.Web;<br />public class CodeBehindClass : System.Web.UI.Page<br />{<br />protected System.Web.UI.WebControls.Label Label1;<br />public void Page_Load(object sender, eventArgs e)<br />{<br />Label1.Text=”Hello World”;<br />}<br />}<br /><br />In the above cod, the .aspx page looks just like the inline page, except the code has been moved to the code-behind file and two more attributes has been added to the Page directive. The <em>Src </em>attribute points to the physical file where the code behind class is located. The <em>Inherits </em>attributes tells us which class in that code-behind file the page should inherit because there technically could be any number of classed in that file. <br />The code-behind class must declare all the controls on the page as <em>protected </em>member of the class.<br />When the first time this page is requested, it will be compiled and cached only as the inline code version, using the code-behind file as the source for its base class. It will remain cached until the .aspx or code-behind file has been changed or the application is restated.<br /><br /><strong>Code-Behind: Compiled</strong><br /><br />This coding style is same as the previous one for the coding point of view except in the Page directive “Src” attribute is replaced with “Codebehind”.<br />e.g.-<br />< %@ Page Language=”C#” Codebehind=”default.aspx.cs” Inherits=”CodeBehindClass” % ><br /><br />Rest of the code will be same as shown in the Code-Behind Non-Compiled coding style.<br />By the way this coding style was used only by Visual Studio 2002 and 2003. <em>Codebehind </em>attribute was used to let the designer know where the code resides. Because no <em>Src </em>was specified, the class indicated in the <em>Inherits </em>attribute had to be compiled in an assembly located in the /bin folder. Actually when the project was built, all the .cs (or .vb) files in the project were compiled into one assembly. When the first time page was requested, it would be compiled in much the same way as the previous method, except that it would inherit from a class compiled in an assembly found in the /bin folder.<br />This style is obsolete and not supported in Visual Studio 2005 as it required constant synchronization between the page and code files that would generate lots of code. It also required a build every time page is tested.<br /><br /><strong>Code-Beside:</strong><br /><br />This coding style uses the concept of partial class to separate the code files from the .aspx page.<br /><br /><strong>Example:</strong><br /><br />default.aspx file:<br /><br />< %@ Page Language=”C#” Codefile=”default.aspx.cs” Inherits=”Default_aspx” % ><br />< html ><br />< body ><br />< form id=”form1” runat=”server” ><br />< asp:Label ID=”Label1” Runat=”server” / ><br />< /form ><br />< /body ><br />< /html ><br /><br />Default.aspx.cs file:<br /><br />using System;<br />using System.Web;<br />public class Default_aspx: System.Web.UI.Page<br />{<br />protected System.Web.UI.WebControls.Label Label1;<br />public void Page_Load(object sender, eventArgs e)<br />{<br />Label1.Text=”Hello World”;<br />}<br />}<br /><br />When a request for the page is made for the first time, the page combines itself with the partial class to become the functional equivalent of the inline code. This compiled page remains valid until one of the involved files is changed.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com2tag:blogger.com,1999:blog-6046577960778787715.post-62600644728542854062010-02-27T01:26:00.000-08:002010-02-27T01:35:57.047-08:00Database Normalization and Normal FormsDatabase can be designed with following approaches:<br /><br /><strong>1. Top-down approach</strong><br /><br />The Entity-Relationship (E/R) modelling technique is the top-down approach. It involves identifying entities, relationships and attributes, drawing E/R diagram and mapping the diagram to tables.<br />Generally tables derived from E/R diagram conforms to at least first normal form. This approach is the best for validation of existing designs.<br /><br /><strong>2. Bottom-up approach</strong><br /><br />Normalizing the database is the bottom-up approach. Normalization is a step by step decomposition of complex tables into simple tables. It reduces redundancy using the principle of non-loss decomposition. Non-loss decomposition is a process of breaking large/complex tables into smaller/simple tables without loss of information.<br />Redundancy is the unnecessary repetition of data that can lead to inconsistencies in data and update anomalies.<br />Generally, normalization follows the process of drawing E/R diagrams.<br /><br /><strong>Note:</strong> A fully normalized record consist set of attributes that describe the entity and a primary key that identifies the entity.<br /><br /><strong>Functional Dependency</strong><br /><br />Normalization theory is based on the theory of functional dependency. <br />Functional dependency can be explained like – <br /><br />Given a relation R, attribute A is functionally dependent on B if each value of A in R is associated with precisely one value of B.<br /><br />OR<br /><br />Given a relation R, attribute A is functionally dependent on B only if whenever two tuples of R agree on their B value, they must agree in their A value as well.<br /><br />For Example – <br />There is an entity named CUSTOMER with following attributes: CODE, NAME, ADDRESS and PHONE_NO.<br /><br />Given a particular value of CODE, there is precisely one corresponding value of NAME, ADDRESS and PHONE_NO. So, the attributes NAME, ADDRESS and PHONE_NO are functionally dependent on the attribute CODE.<br /><br />Functional dependency does not require an attribute to be the key in order to functionally determine other attributes.<br /><br />For Example- <br />In the SALES entity that has attributes: CUSTOMER_CODE, CITY, PRODUCT_CODE, and QUANTITY.<br /><br />CUSTOMER_CODE functionally determines CITY because city to which the shipment is made is also where the customer is located.<br /><br /><strong>Note:</strong> Functional dependency represents many-to-many relationships.<br /><br /><strong>Normal Forms</strong><br /><br />Normalization results in the formation of tables that satisfied certain specified constraints, and represent certain normal forms. Normal forms are table structures with minimum redundancy.<br /><br />Some of the most important and widely used normal forms are:<br /><br />1.First Normal Form (1st NF)<br />2.Second Normal Form (2nd NF)<br />3.Third Normal Form (3rd NF)<br />4.Boyce-Codd Normal Form (BCNF)<br /><br /><strong>Note:</strong> A relation that is in the first normal form may also be in second normal form or third formal form.<br /><br /><strong>First Normal Form</strong> <br /><br />A table is said to be in the first normal form (1 NF) when each cell of the table contains precisely one value. To put data in 1 NF, all repeating information has to be removed.<br /><br /><strong>Second Normal Form</strong><br /><br />A table is said to be in 2 NF when it is in the 1 NF and every attribute in the record is functionally dependent upon the whole key, and not just part of the key.<br /><br />Example- A table has following attributes: EMP_CODE, DEPT, PROJ_CODE, and HOURS.<br /><br />The primary key here is composite(EMP_CODE+PROJ_CODE). But the attributes of this table depend upon only part of the primary key.<br /><br />• EMP_CODE+PROJ_CODE functionally determines HOURS<br />• EMP_CODE functionally determines DEPT but it has no dependency on PROJ_CODE.<br /><br /><strong>Solution:</strong> Break this table into 2 tables: <br />Table A with attributes EMP_CODE and DEPT <br />Table B with attributes EMP_CODE, PROJ_CODE and HOURS.<br /><br /><strong>Third Normal Form</strong><br /><br />A table is said to be in 3 NF when it is in 2 NF and every non-key attribute is functionally dependent on just the primary key.<br /><br />Example- A table has following attributes: EMP_CODE, DEPT and DEPT_HEAD_CODE<br /><br />The primary key here is EMP_CODE. The attribute DEPT is dependent on EMP_CODE and the attribute DEPT_HEAD_CODE is dependent on DEPT. So there is an indirect dependency on primary key.<br /><br /><strong>Solution:</strong> Break the table into 2 tables: <br />Table A with attributes EMP_CODE and DEPT <br />Table B with attributes DEPT and DEPT_HEAD_CODE<br />Now each non-key attribute depends on the key, the whole key and nothing but the key<br /><br /><strong>Boyce-Codd Normal Form</strong><br /><br />A table is said to be in BCNF if every determinate is a candidate key.<br /><br />The definition of 3 NF is inadequate for the tables with multiple candidate keys where they are composite keys or they are overlapped (has at least one attribute in common)<br /><br />Example- Table A has following attributes: EMP_CODE, EMP_EMAIL, PROJ_CODE and HOURS<br /> Table B, which is master for table A has following attributes: EMP_CODE, EMP_EMAIL, EMP_PHONE, EMP_FAX etc.<br /><br /><strong>Observations:</strong><br />• Table A has multiple candidate keys- attributes EMP_CODE and EMP_EMAIL are candidate keys.<br />• Table B has composite candidate keys- EMP_CODE and PROJ_CODE functionally determine HOURS.<br />• And EMP_EMAIL and PROJ_CODE functionally determine HOURS as well.<br />• Composite keys are overlapped – PROJ_CODE is common.<br /><br /><strong>Solution:</strong> Break table into 2 tables:<br />Table B1 with attributes EMP_CODE and EMP_EMAIL<br />Table B2 with attributes EMP_CODE, PROJ_CODE and HOURSsanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-73695486872040464602009-12-26T21:35:00.000-08:002009-12-27T08:25:13.869-08:00Error: "The project type is not supported by this installation."There could be many cases that cause this error. One such case is when you try to open/migrate web project application developed in Visual Studio 2003 in the Visual Studio 2005. The reason being VS 2005 does not come with web project template because VS 2005 comes with new web application development & compilation machanism that is called website model. for more details <a href='http://sanjaysainitech.blogspot.com/2008/06/how-to-create-web-project-in-vs-2005.html'>click</a> here.<br /><br />So to solve this problem you will have to install following updates on your machine.<br /><br />1. <a href='http://www.microsoft.com/downloads/details.aspx?FamilyId=8B05EE00-9554-4733-8725-3CA89DD9BFCA&displaylang=en'>Microsoft Visual Studio 2005 - Update to Support Web Application Projects</a><br />2. <a href='http://www.microsoft.com/downloads/details.aspx?familyid=bb4a75ab-e2d4-4c96-b39d-37baf6b5b1dc&displaylang=en'>install Microsoft® Visual Studio® 2005 Team Suite Service Pack 1</a><br /><br />Note - To fully enable Web Application Projects in Visual Studio 2005, you will have to install both these updates.<br /><br />Reference- http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspxsanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-67132554814296138652009-12-05T21:14:00.000-08:002009-12-05T21:19:21.992-08:00Redirecting Assembly Versions<strong>How to redirect an application to run against newer version of an assembly. </strong><br /><br />An application configuration file, machine configuration file, or a publisher policy file can redirect one version of an assembly to another. You can use the .NET Framework Configuration tool (Mscorcfg.msc) to redirect assembly versions at both the application level and the machine level, or you can directly edit the configuration file.<br /><br />Note: You cannot redirect versions for assemblies that are not strong-named. The common language runtime ignores the version for assemblies that are not strong-named.<br /><br /><strong>Redirecting Assembly Versions Using Publisher Policy</strong><br /><br />Vendors of assemblies can state that applications should use a newer version of an assembly by including a publisher policy file with the upgraded assembly. The publisher policy file, which is located in the global assembly cache, contains assembly redirection settings. Vendors use publisher policies only when the new assembly is backward compatible with the assembly being redirected.<br /><br />You can bypassing Publisher Policy by using following tag in the app.config/web.config files.<br /><br />< publisherPolicy apply="no" ><br /><br /><strong>Redirecting Assembly Versions through App.config/Web.config files</strong><br /><br />Specify information for an assembly by placing information for each assembly inside a <dependentAssembly> element. The <assemblyIdentity> element contains information that identifies an assembly. You can have more than one <dependentAssembly> element in the configuration file, but there must be exactly one <assemblyIdentity> element in each <dependentAssembly> element. To redirect one version to another, use the <bindingRedirect> element. The oldVersion attribute can specify either a single version, or a range of versions. For example, <bindingRedirect oldVersion="1.1.0.0-1.2.0.0" newVersion="2.0.0.0"/> specifies that the runtime should use version 2.0.0.0 instead of the assembly versions between 1.1.0.0 and 1.2.0.0.<br /><br />Example:<br /><br />< configuration ><br /> < runtime ><br /> < assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" ><br /> < dependentAssembly ><br /> < assemblyIdentity name="myAssembly" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" / ><br />< !-- Assembly versions can be redirected in application, publisher policy, or machine configuration files. -- ><br /> < bindingRedirect oldVersion="1.0.0.0"<br /> newVersion="2.0.0.0"/ ><br /> < / dependentAssembly ><br /> < dependentAssembly ><br /> < assemblyIdentity name="mySecondAssembly" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" / ><br />< !-- Publisher policy can be set only in the application configuration file. -- ><br /> < publisherPolicy apply="no" ><br /> < / dependentAssembly ><br /> < / assemblyBinding ><br /> < / runtime ><br />< / configuration > <br /><br />Note: The <assemblyBinding> elements are order-sensitive. You should enter assembly binding redirection information for any .NET Framework version 1.0 assemblies first, followed by assembly binding redirection information for any .NET Framework version 1.1 assemblies<br /><br />Reference: http://msdn.microsoft.com/en-us/library/7wd6ex19(VS.71).aspxsanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-14742344627925051342009-06-02T10:32:00.000-07:002009-06-02T10:35:29.673-07:00Publish Website: Access to the path ...\App_WebReferences.compiled' is denied.This error sometimes comes during publishing website that implements impersonation. When impersonation setting is made in the web.config file and the impersonate user dose not have access permission on the temp directory, this error likely to come. Although I don’t understand why impersonate user needs access permission on temp directory because during publishing website is precompiled and copied in the given location.<br /> <br />Anyways the solution that worked for me is that I commented the impersonation setting in the web.config file and then published it after publishing succeed I uncommented the settings from the web.config file in the published folder.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com2tag:blogger.com,1999:blog-6046577960778787715.post-30901079610061201972009-05-08T12:15:00.000-07:002009-05-08T12:20:02.647-07:00HTTP Modules Versus Global.asax FilesYou can implement much of the functionality of a module in the application's Global.asax file, which enables you to respond to application events. However, modules have an advantage over the Global.asax file because they are encapsulated and can be created one time and used in many different applications. By adding them to the global assembly cache and registering them in the Machine.config file, you can reuse them across applications. For more information, see Global Assembly Cache. <br /><br />The advantage of using the Global.asax file is that you can handle other registered events such as Session_Start and Session_End. In addition, the Global.asax file enables you to instantiate global objects that are available throughout the application. <br />You should use a module whenever you must create code that depends on application events, and when the following conditions are true: <br /># You want to re-use the module in other applications. <br /># You want to avoid putting complex code in the Global.asax file. <br /># The module applies to all requests in the pipeline (IIS 7.0 Integrated mode only). <br />You should add code in the Global.asax file whenever you must create code that depends on application events and you do not have to reuse it across applications. You can also use the Global.asax file when you have to subscribe to events that are not available to modules, such as Session_Start. <br /> <br />Global.asax file is derived from HttpApplication class and it does not implement IHttpModule interface like custom modules. If you are not going to use your custom module in any other application or don’t have complex logic than you should use Global.asax instead of creating custom modules.<br />You can have multiple modules in your web application implementing same events. Modules are called in the sequence they are added in the web.config file. With in a module events are called in following sequence:<br /> <br />BeginRequest <br />AuthenticateRequest <br />AuthorizeRequest <br />ResolveRequestCache <br />AcquireRequestState <br />PreRequestHandlerExecute <br />PostRequestHandlerExecute <br />ReleaseRequestState <br />UpdateRequestCache <br />EndRequest <br />PreSendRequestHeaders<br />PreSendRequestContent<br />Error <br /><br /><strong>Event calling sequence in multi module Scenario: </strong><br />Suppose there are Global.asax and 2 custom modules namely Module.cs and Module1.cs in an application. Custom modules are added in web.config in following order.<br /> <br /> < httpModules ><br /> < add name="MyModule1" type="MyModule1" /><br /> < add name="MyModule" type="MyModule" /><br /> < /httpModules ><br /> <br />And all of them are handling first 3 event in the above given list – BeginRequest , AuthenticateRequest, AuthorizeRequest.<br /> <br />The sequence of event call will be as follows:<br /> <br />Application_Start - Global.asax<br />Init - Global.asax <br />BeginRequest - MyModule1<br />BeginRequest - MyModule<br />BeginRequest - Global.asax<br />AuthenticateRequest - MyModule1<br />AuthenticateRequest - MyModule<br />AuthenticateRequest - Global.asax<br />AuthorizeRequest - MyModule1<br />AuthorizeRequest - MyModule<br />AuthorizeRequest - Global.asax<br />Session_Start - Global.asax<br />Page_Loadsanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1tag:blogger.com,1999:blog-6046577960778787715.post-5875084578846980612009-05-08T12:11:00.000-07:002009-05-08T12:14:09.992-07:00What is the difference between ETL tool and OLAP tool?<strong>ETL: </strong><br />Extract, Transform and Load. This is a product to extract the data from multiple/single source transform the data and load it into a table, flat file or simply a target.<br />There is a quite a bit competition in the market with regard to the ETL product as well as the OLAP products. These tools would definitely be widely used for data load and data analysis purpose. <br />ETL tools in market<br /><br />1 INFORMATICA-- univeral tool good market<br />2 ABINITO -- fastest loading tool very good market<br />3 DATASTAGE-- difficult work no good market<br />4 BODI-- good market<br />5 ORACLE WAREHOUSE BUILDER-- good market<br /><br />ETL Tools is for Extracting source data, Transforming as required and Loading into DW. it is first part of DW. Now large fact and dimension tables are in DW. If you have to generate crosstab report from these tables, it will take very long time. So these DW tables are transformed into Cubes and stored in OLAP Server. Any Report Generation, Analysis is done on these... Cubes are having pre aggregated values and hence Report Generation will be much faster. <br /><br /><strong>OLAP:</strong> <br />Its an online analytical processing tool. There are various products available for data analysis. Like Hyperion which is a Business Intelligence (BI) and Business Performance Management (BPM ) Tool like Brio, Business Objects and Cognos etc. Its the market leader in Financial, Operational and Strategic Planning. It has applications for Planning, consolidation, scorecarding, reporting, dashboards, Analysis, Workspace, Master Data Management and Foundation. <br /><br /><strong>The Difference between the two:</strong><br />There are only 2 ways available to get data from a datawarehouse or a database.one is using sql statement and other method is using an OLAP tool(ex:cognos, business objects.....)So Hyperion is an example for a OLAP tool. ETL is a process of Extracting data from a source systems(a system where client's transactional business information resides) and performing business logic(applying TRANSFORMATION rules) on the collected source information(business logic depends on business requirements), and LOADING the precise data into a warehouse(probably a relational database). OLAP comes into picture after ETL developers design the warehouse........by using olap tools a business user can generate standard reports(without having sql knowledge he can do this)sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com2tag:blogger.com,1999:blog-6046577960778787715.post-38577109482670103692009-05-08T11:51:00.000-07:002009-05-08T12:09:43.419-07:00How to configure application services in asp.netHere I am not going to explain what is application service in asp.net, for that you can see my post -<a href='http://sanjaysainitech.blogspot.com/2008/01/using-web-parts-with-sql-server-2000.html'><br />Using Web Parts with SQL Server 2000/2005.</a><br />Configuring application services in your asp.net application is a two step process:<br /><br />1. Configure database objects that will hold application services data.<br />2. Configure providers that will provide access to application services data from the database.<br /><br />For Configure database objects use following sql script that will create database & its objects(tables, Sps) for storing application services objects. <br />These are found at <root>:\WINDOWS\Microsoft.NET\Framework\v2.0.50727<br /><br />InstallCommon.sql<br />InstallMembership.sql<br />InstallPersonalization.sql<br />InstallProfile.sql<br />InstallRoles.sql<br /><br />Make sure you run "InstallCommon.sql" script first as it creates database before running other scripts. By default database name is "aspnetdb" but if you want to change it, you can update InstallCommon.sql script.<br />These sql scripts are handy if you dont want to use all application services or you dont want to create separate database for it. In that case you can run any one or all script(s) depending upon the service you want to use on your application database. like if you want to implement only personalization then you just need to run "InstallPersonalization.sql" on your main database.<br /><br />You can unstall these objects as well using following sql scripts.<br /><br />UninstallCommon.sql<br />UninstallMembership.sql<br />UninstallPersonalization.sql<br />UninstallProfile.sql<br />UninstallRoles.sql<br /><br />For example you may want to use only personization service not profile, membership and role service in that case there is no point to have other services configured in the application.<br />So you can run InstallCommon.sql followed by InstallProfile.sql sql scripts.<br />Note:- dont forget to change database name in the InstallCommon.sql sql script with the database in which you want to configure application service data objects.<br /><br />You can do same thing using aspnet_regsql.exe utility as well using following command at the command prompt.<br /><br />aspnet_regsql.exe -S < server name > -U < username > -P < password > -A < service code > -d < database name ><br /><br />service code - all : all services<br /> m : membership<br /> r : role manager<br /> p : profile<br /> c : personalization<br /> w : sql web event provider<br /><br />For example if you have to add only profile service in your existing database, run following command at the command prompt:<br /><br />aspnet_regsql.exe -S myserver -U user1 -P pass1 -A p -d mydb<br /><br />Note:- replace server name, user name, password and database name with user's.<br /><br />To remove profile service use -R in place of -A<br /><br />Like:- aspnet_regsql.exe -S myserver -U user1 -P pass1 -R p -d mydb<br /><br />----------------------------------------------------------<br /><br />Second step is to configure providers in the web application. <br />Below is the code sample that can be added in the web.config file depending upon the application service you want to configure in your web application.<br /><br />Provider's configuration in web.config file.<br /><br />< !-- Connection string will point to the database that is configured to store application service data -- ><br />< connectionStrings ><br />< add name="SQLConnString" connectionString="Data Source=FN-WS282-D8;Initial Catalog=AppServices;Integrated Security=false; user id=sa; pwd=pass1" providerName="System.Data.SqlClient" /><br />< /connectionStrings ><br /><br />< !-- Add following code for configuring personalization in the web.config file -- ><br />< webParts ><br />< personalization defaultProvider="SqlPersonalizationProvider" ><br />< providers ><br />< add name="SqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="SQLConnString" applicationName="/" /><br />< /providers ><br />< authorization ><br />< deny users="*" verbs="enterSharedScope" /><br />< allow users="*" verbs="modifyState" /><br />< /authorization ><br />< /personalization ><br />< /webParts ><br /><br />< !-- Add following code for configuring profile in the web.config file -- ><br />< profile defaultProvider="SqlProfileProvider" ><br />< providers ><br />< clear /><br />< add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SQLConnString" applicationName="/" /><br />< /providers ><br />< properties ><br />< add name="Message" type="System.String" /><br />< /properties ><br />< /profile ><br /><br />< !-- Add following code for configuring membership in the web.config file -- ><br />< membership defaultProvider="SqlMembershipProvider" ><br />< providers ><br />< clear /><br />< add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SQLConnString" applicationName="/" /><br />< /providers ><br />< /membership ><br /><br />< !-- Add following code for configuring role manager in the web.config file -- ><br />< roleManager defaultProvider="SqlRoleProvider" ><br />< providers ><br />< clear /><br />< add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="SQLConnString" applicationName="/" /><br />< /providers ><br />< /roleManager >sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-63837569764603023122009-04-23T10:52:00.000-07:002009-04-23T11:09:43.481-07:00Pass by reference to a Web ServiceFew days back someone asked me if we can pass value by reference to a web method. I thought why would some one want to pass parameter's reference to a web method because parameter's reference will point to memory location in client machine whereas web method will be invoked on the server machine where that reference will be invalid. <br />Anyways, the reality is that you can pass value by reference to a web method if it allows so. In fact you can also create web method that will take "out" parameter.<br /><br />In Web Methods parameters can be passed by reference using “ref” keywords just like any other method.<br />Like – <br /> [WebMethod]<br /> public void WebMethod2(ref int iparam)<br /> {<br /> iparam = iparam + 100;<br /> }<br /> <br />And in the proxy class at the client end it is declared as below:<br /> <br /> public void WebMethod2(ref int iparam)<br /> {<br /> object[] results = this.Invoke("WebMethod2", new object[] {iparam});<br /> iparam = ((int)(results[0]));<br /> }<br /><br /><br />Web Methods can also have “out” parameters.<br />Like -<br /> [WebMethod]<br /> public string WebMethod1(string str,out int iReturn)<br /> {<br /> string temp = "Hello " + str;<br /> iReturn = temp.Length;<br /> return temp;<br /> }<br /> <br />And in the proxy class at the client end it is declared as below:<br /> <br /> public string WebMethod1(string str, out int iReturn)<br /> {<br /> object[] results = this.Invoke("WebMethod1", new object[] {str});<br /> iReturn = ((int)(results[1]));<br /> return ((string)(results[0]));<br /> }sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-32925300571079620652009-04-23T09:57:00.000-07:002009-04-23T10:05:54.850-07:00Error: A name was started with an invalid character.Sometimes when we try to browse our newly hosted website or web service, we encounter with this error. The reason is that we forgot to configure ASP.NET version in the IIS or selected wrong version when we were hosting it.<br /> <br />So now its time to correct this issue, follow these steps:<br /> <br />1. Open IIS management console. <br />2. Right click on the virtual directory of your web service and choose properties from the shortcut menu. <br />3. Now click on the ASP.NET tab and choose appropriate ASP.NET version from the dropdown. <br />4. Now click on Apply button to apply new setting and then click on OK button. <br /> <br />Now try again to access you website/web service, you should be able to do so…sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com0tag:blogger.com,1999:blog-6046577960778787715.post-22813537624976959162009-04-22T10:34:00.000-07:002009-04-23T10:11:56.792-07:00Facts about Web Services1. Web service class can have overloaded constructors (parameterized) but client can use only default parameter less constructor to instantiate web service object.<br />2. service constructor(s) can not be made web method using “WebMethod” attribute.<br />3. If web services is updated then the client needs to updated the web reference to get the changes reflected in the proxy class and if the change affecting any web method call in the client then client needs to be rebuilt after code change as well.<br />4. Web methods can have public, private, protected, internal and protected internal access modifiers but only public web method will be exposed to the client.<br />5. Web service class could be public or internal. [Class can not be declared as private, protected or protected internal].<br />6. Web method could be declared as virtual method.<br />7. Public class can not be derived from web service class as it lessens the accessibility of base web service class. But you can derive non public class. <br />8. Web service class can have non “[WebMethod]” functions as well.<br />9. Web service class can implement interface and declare implemented interface function as “[WebMethod]” so they can be exposed to clients.<br />10. Web Method can be declared as static but then it will not be exposed to client.<br />11. Web Service class can be declared as sealed class.sanjay sainihttp://www.blogger.com/profile/03018435962450831911noreply@blogger.com1