Wednesday 30 March 2016

What is eager loading in Entity Framework?

It is the process in which related objects are loaded automatically with parent objects. We can also say that a query of one type of entity load related entity as part of query.
For Example we have School Database in which Student, Address etc. Tabled or entities are there. While fetching of Student table data, at the same time we want to load Address table data also.
Sample:-
SchoolDBContext   db= new SchoolDBContext();
var res=db.Student.Include(“Address”).Take(10);
foreach(var  student  in  res)
{
     Console.WriteLine(student.Name);
     foreach(var  address  in  Student.Address)
     {
           Console.WriteLine(address.PamanentAddress);
     }
}

What is entity framework?

Entity Framework (EF) is an object –relational mapper that enables .NET developers to work with the relational data using domain specific objects. It eliminates the need for most of the data-access code that the developers usually need to write.

Using Entity Framework, developers issues queries using LINQ, then retrieves and manipulates data as strongly type objects.

Entity Framework is an Object/Relational Mapping (O/RM) framework. We can say that it is an enhancement of ADO.Net that gives developers an automated mechanism for accessing and storing the data in the database.

Entity Framework is useful in three scenarios:-
·         If you have already a existing database.
·         If you want to focus on your domain classes and then create a database from your domain class.
·         Design your schema on the visual designer and then create database and classes.
 

Wednesday 9 March 2016

ISNULL VS COALESCE ?



ISNULL function is a Transact-SQL function while COALESCE function in an ANSI SQL standard.
ISNULL function contains only two parameters while COALESCE function contains multiple parameters.

Example:- 
Select ISNULL(null,'Hello')
Select coalesce(null,null,'hello')

ISNULL function looks at first value and second parameter value is automatically limit to the length of first parameter but COALESCE do not have this restriction.


Example:- 

Declare @test varchar(4)
Select ISNULL(@test,'abcde') – give abcd
Select coalesce(@test,'abcde')—give  abcde

ISNULL function contains different type of data types while COALESCE function parameter should have same datatype.


Example:- 

Declare @a varchar(5)='abcd'
Declare @b int=5
Select ISNULL(@a,@b)--- compiled
Select coalesce(@a,@b) --- give error

what is Autopostback in asp.net?


AutoPostBack is the mechanism , by which the page will be posted back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, which is set to true, will send the request to the server when an event happens in the control.

Example:-
TextBox has AutoPostBack property.
The AutoPostBack property is used to set or return whether or not an automatic post back occurs when user presses “ENTER” or “TAB” in the TextBox control.