Creating ASP.NET MVC 5 Application using Entity Framework 6 and Identity with CRUD Operations on visual studio 2015 - Part 2

This is the part-2  of creating ASP.NET MVC 5 application using entity framework and identity with crud operations from scratch. Before creating entity framework model first create your SQL server database. For SQL server database you need  to install the SQL server 20118/2012/2014.  If you have any query please feel free and post a comment right below. Other part of series:
  1. Creating ASP.NET MVC 5 project Part-1?
  2. Creating SQL Server database Part-2?
  3. Creating Entity Framework project Part-3 ?
  4. Customize the default template of ASP.NET MVC 5 Part-4 ?
  5. How to add a controller and view Part-5 ?
  6. How to Add Model Part-6 ?
  7. How to make a patient registration form Part-7?
  1. Creating your SQL server database
    • Let's create a SQL database, open your SQL server and right click on Databases then go to the New database option.
    • New database window will appear then simply enter the name of database HIMS.DB and click OK.
    • Your database will be appear on the left side if not then refresh the database. Add a table in your database by right clicking on the tables and go to table.
  • So let's create Patient table by entering all the attributes of Patient. Then simply save the table (Ctrl+S) and enter the name of table Patient then click OK. Refresh the database your Patient table is created successfully.
    • Like a Patient table create a Country table e.g.
    • Province table.
    • District table.
    • City Table.
    • If you know how to create a database in SQL server then simply copy the following script and paste it into new query window finally run the query and refresh the database. Your database is created successfully.
      USE [master] GO
      /****** Object: Database [HIMS.DB] Script Date: 9/11/2017 3:49:33 PM ******/
      CREATE DATABASE [HIMS.DB]
      CONTAINMENT = NONE
      ON PRIMARY
      ( NAME = N'HIMS.DB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\HIMS.DB.mdf' ,
      SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
      LOG ON
      ( NAME = N'HIMS.DB_log', FILENAME = N'C:\Program Files\Microsoft SQL
      Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\HIMS.DB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
      GO
      ALTER DATABASE [HIMS.DB] SET COMPATIBILITY_LEVEL = 120
      GO
      IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
      begin
      EXEC [HIMS.DB].[dbo].[sp_fulltext_database] @action = 'enable'
      end
      GO
      ALTER DATABASE [HIMS.DB] SET ANSI_NULL_DEFAULT OFF
      GO
      ALTER DATABASE [HIMS.DB] SET ANSI_NULLS OFF
      GO
      ALTER DATABASE [HIMS.DB] SET ANSI_PADDING OFF
      GO
      ALTER DATABASE [HIMS.DB] SET ANSI_WARNINGS OFF
      GO
      ALTER DATABASE [HIMS.DB] SET ARITHABORT OFF
      GO ALTER DATABASE [HIMS.DB] SET AUTO_CLOSE OFF GO
      ALTER DATABASE [HIMS.DB] SET AUTO_SHRINK OFF
      GO
      ALTER DATABASE [HIMS.DB] SET AUTO_UPDATE_STATISTICS ON
      GO
      ALTER DATABASE [HIMS.DB] SET CURSOR_CLOSE_ON_COMMIT OFF
      GO
      ALTER DATABASE [HIMS.DB] SET CURSOR_DEFAULT GLOBAL
      GO
      ALTER DATABASE [HIMS.DB] SET CONCAT_NULL_YIELDS_NULL OFF
      GO
      ALTER DATABASE [HIMS.DB] SET NUMERIC_ROUNDABORT OFF
      GO
      ALTER DATABASE [HIMS.DB] SET QUOTED_IDENTIFIER OFF
      GO
      ALTER DATABASE [HIMS.DB] SET RECURSIVE_TRIGGERS OFF
      GO
      ALTER DATABASE [HIMS.DB] SET DISABLE_BROKER
      GO
      ALTER DATABASE [HIMS.DB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
      GO
      ALTER DATABASE [HIMS.DB] SET DATE_CORRELATION_OPTIMIZATION OFF
      GO
      ALTER DATABASE [HIMS.DB] SET TRUSTWORTHY OFF
      GO
      ALTER DATABASE [HIMS.DB] SET ALLOW_SNAPSHOT_ISOLATION OFF
      GO
      ALTER DATABASE [HIMS.DB] SET PARAMETERIZATION SIMPLE
      GO
      ALTER DATABASE [HIMS.DB] SET READ_COMMITTED_SNAPSHOT OFF
      GO
      ALTER DATABASE [HIMS.DB] SET HONOR_BROKER_PRIORITY OFF
      GO
      ALTER DATABASE [HIMS.DB] SET RECOVERY SIMPLE
      GO
      ALTER DATABASE [HIMS.DB] SET MULTI_USER
      GO
      ALTER DATABASE [HIMS.DB] SET PAGE_VERIFY CHECKSUM
      GO
      ALTER DATABASE [HIMS.DB] SET DB_CHAINING OFF
      GO
      ALTER DATABASE [HIMS.DB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
      GO
      ALTER DATABASE [HIMS.DB] SET TARGET_RECOVERY_TIME = 0 SECONDS
      GO
      ALTER DATABASE [HIMS.DB] SET DELAYED_DURABILITY = DISABLED
      GO
      USE [HIMS.DB]
      GO
      /****** Object: Table [dbo].[City] Script Date: 9/11/2017 3:49:33 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      CREATE TABLE [dbo].[City](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [DistrictId] [int] NULL,
      [Name] [nvarchar](100) NULL,
      CONSTRAINT [PK_City] PRIMARY KEY CLUSTERED
      (
      [Id] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
      ON) ON [PRIMARY]
      ) ON [PRIMARY]
      GO
      /****** Object: Table [dbo].[Country] Script Date: 9/11/2017 3:49:33 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      SET ANSI_PADDING ON
      GO
      CREATE TABLE [dbo].[Country](
      [CountryID] [int] IDENTITY(1,1) NOT NULL,
      [Name] [varchar](50) NULL,
      [Code] [nvarchar](50) NULL,
      CONSTRAINT [PK_TblCountry] PRIMARY KEY CLUSTERED
      (
      [CountryID] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
      ON) ON [PRIMARY]
      ) ON [PRIMARY]
      GO
      SET ANSI_PADDING OFF
      GO
      /****** Object: Table [dbo].[District] Script Date: 9/11/2017 3:49:33 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      SET ANSI_PADDING ON
      GO
      CREATE TABLE [dbo].[District](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Name] [varchar](50) NULL,
      [ProvinceId] [int] NULL,
      CONSTRAINT [PK_TblDistrict] PRIMARY KEY CLUSTERED
      (
      [Id] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
      ON) ON [PRIMARY]
      ) ON [PRIMARY]
      GO
      SET ANSI_PADDING OFF
      GO
      /****** Object: Table [dbo].[Patient] Script Date: 9/11/2017 3:49:33 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      CREATE TABLE [dbo].[Patient](
      [Id] [int] NOT NULL,
      [MRN] [nvarchar](50) NULL,
      [FName] [nvarchar](50) NOT NULL,
      [MName] [nvarchar](50) NULL,
      [LName] [nvarchar](50) NULL,
      [Gender] [nvarchar](8) NULL,
      [DOB] [datetime] NULL,
      [Marital_Status] [nvarchar](50) NULL,
      [CountryId] [int] NULL,
      [ProvinceId] [int] NULL,
      [DistrictId] [int] NULL,
      [CityId] [int] NULL,
      [PrimaryAddress] [nvarchar](100) NULL,
      [SecondaryAddress] [nvarchar](100) NULL,
      [MobilePhone] [nvarchar](50) NOT NULL,
      [WorkPhone] [nvarchar](50) NULL,
      CONSTRAINT [PK_Patient] PRIMARY KEY CLUSTERED
      (
      [Id] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
      ON) ON [PRIMARY]
      ) ON [PRIMARY]
      GO
      /****** Object: Table [dbo].[Province] Script Date: 9/11/2017 3:49:33 PM ******/
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      SET ANSI_PADDING ON
      GO
      CREATE TABLE [dbo].[Province](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Name] [varchar](50) NULL,
      [CountryId] [int] NULL,
      CONSTRAINT [PK_TblProvince] PRIMARY KEY CLUSTERED
      (
      [Id] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
      ON) ON [PRIMARY]
      ) ON [PRIMARY]
      GO
      SET ANSI_PADDING OFF
      GO
      USE [master]
      GO
      ALTER DATABASE [HIMS.DB] SET READ_WRITE
      GO
    • In part 3 learn how to create entity model and how to connect entity model with SQL server.

No comments:

Post a Comment

Creating ASP.NET MVC 5 Application using Entity Framework 6 and Identity with CRUD Operations on visual studio 2015 Part-9

This is the part-9 of asp.net mvc 5 series using entity framework and identity from scratch.In this tutorial you will learn how to bind a...