Entity Framework with MVC WebApp.

Assalamualaykum Wr Br..:)
Today we build MVC web app. with Entity Framework. Lets add new table TblEmployee in EF_DBFirst database as shown below:
The respective script is:
CREATE TABLE [dbo].[TblEmployee] (
[Id]     INT          NOT NULL,
[Name]   VARCHAR (50) NOT NULL,
[Gender] VARCHAR (50) NOT NULL,
[City]   VARCHAR (50) NOT NULL,
Now create new application of MVC_EF and add new controller EmployeeController.cs, Employee.cs in Model, EmployeeContext.cs in Model and Display.cshtml in Views/Employee. As per the table design generate a class with name Employee.cs in Model as shown below:
In above class, Table attribute describes class Employee as per the table TblEmployee and Table attribute exists in System.ComponentModel.DataAnnotations.Schema namespace. Now we need to create connection string which is done in web.config as shown:
Please notice that we have provided name=”EmployeeContext”hence we create a dbcontext class as shown below with name EmployeeContext.cs where we define property which returns whole data of table employee.
Now focus on controller class which is responsible for routing the user requests and response. Design the controller class as shown below:
In controller we create employeecontext class object and access single record with respect to id passed from frontend as a parameter to Details Controller. The Linq query is                                      (emp => emp.Id == id)
emp is temporary variable which cross checks with parameter id with existing db Id, if matches then displays data of record and returns to view. view is designed as shown:
the first line of above states that this view accesses model Employee and @Model.Name is retrieved from db table. Finally if i pass the url the following output is seen.


Thats all for the day.Jazakallah Khair.



What is Entity Framework..?

Assalamualaykum wr br..:
Today we discuss what EF is..?
EF is ORM framework. ORM -> Object Relational Mapping. ORM automatically creates classes based on Database tables, and vice versa is also true. ie. it can also automatically generate SQL to create database tables based on classes.
Lets start a small project on it to understand better. To achieve it,
1. Create Department and Employee Classes.
2. Write ADO.Net code to retrieve data from the database.
3. Need to create objects of Department and classes to populate data.
Entity Framework can do all the above statements automatically , if we provide it with database shema.
Create the Database and tables as shown below:
Now add the Ado.net Entity Data Model and name it as EmployeeModel.edmx file and this results in wizard, supply the necessary values and finish.
compile the solution and add new webform in which add gridveiw and entity datasource control and then configure the Entity datasource with database and tables of employee and department and allow it to generate from database.
Thats it for the day..also  please have a look on the versions of EF.
The following table lists all the important versions of Entity Framework.

EF Version Introduced Features
EF 3.5 Basic O/RM support with Database First approach.
EF 4.0 POCO Support, Lazy loading, testability improvements, customizable code generation and the Model First approach.
EF 4.1 First to available in the NuGet, Simplified DBContext API over ObjectContext, Code First approach. EF 4.1.1 patch released with bug fixing of 4.1.
EF 4.3 Code First Migrations feature that allows a database created by Code First to be incrementally changed as your Code First model evolves. EF 4.3.1 patch released with bug fixing of EF 4.3.
EF 5.0 Announced EF as Open Source. Introduced Enum support, table-valued functions, spatial data types, multiple-diagrams per model, coloring of shapes on the design surface and batch import of stored procedures, EF Power Tools and various performance improvements.
EF 6.0 – Current release EF 6.0/6.1 is the latest release of Entity Framework. It includes many new features related to Code First & EF designer like asynchronous query & save, connection Resiliency, dependency resolution etc.

Entity Framework Webapp

Assalamualaykum wr br..:)
Today we are discuss about the code first approach of EF where code is designed based on which database is generated with tables and keys.
Lets quick start with web application. Create New Project -> WebSite -> <NameApp>.
Create the two classes in separate files Employee and Department also add two more classes with names as EmployeeDBContext.cs and EmployeeRepository.cs as shown

Code the Employee class as shown below. Every Employee is associated with Department hence it is defined using Department property whose return type is Department and as it is available in both tables(Classes) hence it is referenced as Navigation Properties and remaining properties like Id, Firstname,  secondname etc are Static Properties.
Now code the Department class as below. Every Department have Id, Name which will be Static Properties and each department holds multiple employees for which list is considered with return type as employee which is navigation properties.


Now lets create EmployeeDBContext.cs class where we create datasets of tables to populate the data as applicable.

To fetch and operate on tables data we need to have one generic class which is referred to as EmployeeRepository.cs as shown below. It has one Get method which populates the department class data and returns.
Finally add new Webform.aspx and drag and drop grid view control and also datasource control as shown below. Before you add webform compile your project to let EF create dlls which is used to reference in datasource control. In above image of employeerepository class we see Include(“Employees”). This Include method used to display Navigation Properties where in Department table Employees is the Navigation Property.
Thats it for the Day..:)    Jazakallah khair

Entity Framework – CodeFirst Approach

Assalamualaykum Wr Br..:)
Today we are going to discuss Entity Framework Code First approach with a simple console application demonstrating  School activities with two classes named as Student & Standard.
As we know student have attributes like StudentId, Name, Standard, Age & Date Of Birth hence we are going to create properties with same name in class Student.
Similarly, Standard class do have properties like StandardId, StandardName but this class can have multiple students hence we are using ICollections of type Student as shown below:
Now I would create a new class with SchoolDBContext name where DBContext is mandatory for flexible default operations with built in libraries of Entity Framework. This DBContext have dataset hence its return type would be Dbset and its properties are classes with s appended atlast with name as shown below:
Finally it is required to call the DBContext class in main method as shown below:
With this Execution of program, Entity Framework creates the New database with tables as designed with classes as shown below:

With this it is observed that based on the code design DB is being generated hence it is regarded as Code First Approach.

Thats it for today..:Jazakallah khair


Installing Hadoop Accumulo

Today we discuss about installing Apache Accumulo on Ubuntu machine.

Download the package from the following link:
$ wget http://www-eu.apache.org/dist/accumulo/1.8.0/accumulo-1.8.0-bin.tar.gz

Extract the package and add the home of $ACCUMULO_HOME in bashrc file as shown:
$ tar zxf accumulo-1.8.0-bin$ gedit ~/.bashrc

Add following lines in bashrc file:
export $ACCUMULO_HOME=<Installation location>

Verify the bashrc file from source ~/.bashrc

Thats it for today..:)

Jazakallah khair

Installing Hadoop HCatalog

Today we discuss about installation of HCatalog on Ubuntu.

Download the software package from the following link and using the command:
$ wget http://www-eu.apache.org/dist/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz

Extract the package using command
$ tar zxf apache-hive-1.2.1-bin.tar.gz

Add the HCAT_HOME parameters in bashrc file( copy and paste the following lines in bashrc file) as shown below:
$ gedit ~/.bashrc
export HCAT_HOME=/home/aejaaz/apache-hive-1.2.1-bin

Verify the added lines of code in bashrc file are valid using source as shown:
$ source ~/.bashrc

Thats it for today..:)

Jazakallah khair


Installing Hadoop HBase On Ubuntu

Assalamualaykum Wr Br..:)

Today we discuss about the installation steps of Hbase on Ubuntu OS.

Download the hbase software from the following link and using the command:
$ wget http://www-eu.apache.org/dist/hbase/0.98.23/hbase-0.98.23-hadoop1-bin.tar.gz

Extract the Package using the command:
$ tar xvf hbase-0.98.23.tar.gz

Edit the bashrc file by adding the HBASE_HOME parameters in it as shown below:
$ gedit ~/.bashrc#HBASE_HOME

verify the bashrc file using command
$ source ~/.bashrc

Thats it for today..:)

Happy Learning..Jazakallah khair