Tuesday, September 3, 2013

Passive Voice

1. Passive with Simple Present

Subject + is/are + past participle.

is <- is used with singuler words.

  • The door is opened.
  • The door is not opened.


are <- is used with plural words.

  • The doors are opened.
  • The doors are not opened.
more examples :
We set the table -> The table is set by use.
"We" thired person singular 
is + past participle.

They don't help you. -> You are not helped by them.
"you" is second person and a negative sentence.
are+ not + past participle.

Does the police office catched the thief -> Is theif caught by the police officer.
"thief" is thired person singuler and sentence is negative.
is + subject + past participle.



2. Passive with Simple Past

Subject + was/were + past participle.

was <- is used with singuler words.
e.g. :

  • The cat was fed.
  • The cat was not fed.


were <- is used with plural words.
e.g. :

  • The cats were fed.
  • The cats were not fed.
more examples.




3. Passive with Present Perfect

Subject + have/has + been + past participle.

has <- is used with singuler words.
e.g. :

  • The door has been closed.
  • The door has not been closed.


have <- is used with plural words.
e.g. :

  • The doors have been closed.
  • The doors have not been closed.

4. Passive with Future I

Subject + will+ be + past participle.

e.g. :

The car will be brought.






Tuesday, August 27, 2013

J Query

 1. What is  J Query?

 It is a JavaScript library.

There are a lots of other JavaScript frameworks out there, but jQuery seems to be the most popular, and also the most extendable.

2. Purpose of J Query?

Purpose is to make it much easier to use JavaScript on your website.
JQuery also simplifies - complicated things from JavaScript, like AJAX calls and DOM manipulation.

3.J Query library features:
  • HTML/DOM manipulation
  • CSS manipulation
  • HTML event methods
  • Effects and animations
  • AJAX
  • Utilities
4.Adding J Query to web pages

Method 1 : Download the jQuery library from jQuery.com  
  1. Two versions of J query to Download
  • Production Version - This is for the live environment.
  • Development Version - This is for the development and Testing environment.
It is a single Java Script File(<script> tags should be inside the head section)

<head>
<script src="jquery-1.10.2.min.js"></script>
</head>  

"text/javascript" is not inside the <script> tag because JavaScript is the default scripting language in HTML5 and in all modern browsers.so this is not required in HTML5.



Method 2 :Include jQuery from a CDN. (This will help the faster loading)

If you don't want to download and host jQuery yourself, you can include it from a CDN (Content Delivery Network).
Both Google and Microsoft host jQuery.

Google CDN

 <head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head

 Microsoft CDN

<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js">

</script>
</head> 

 

 




WCF Thing's To Remember

Ref: http://www.codeproject.com/Articles/28892/Asp-Net-Interview-Question-Part-1#Howdoweassignpagespecificattributes

1) What is WCF?

It is the unification of all the .net technologies.It is mainly used to solve the problem of  using several different technologies into one application.

2) What are the technologies it uses?

.NET Remoting ( If a system is using distributed architecture and All the client's are based on the windows platform and hosted on windows platform)

Web Services (If a system is using distributed architecture and Clients using different OS's(Non Microsoft OS and Microsoft Os)  to connect to the distributed application)

MSMQ (To improve  a system with Queue facility to solve synchronous processing problems. )

COM+(To implement package handling mechanisms)

3) WCF Based on which architecture?

It is based on the SOA (Service Oriented Architecture)

4) What are the important concepts behind the SOA?

Boundaries are well defined
  • The client who is consuming the service does not need to know how the implementation of the service is done.
  • In SOA the rule is if you do enhancement you do not need to change anything at the client. 
  • SOA based application only understands that there is an end point, contract and bindings.
Services evolve(expand gradually)
  • When the services are changing,it will not impact on the services who are consuming the current version of application.
  • In SOA services can be versioned and you can host those services in new end points.
Services share only Schemas and Contracts
  • Services use Schemas to represent data 
  • Services use contracts to understand behavior. 
  • XML is used to define schemas and contracts.(Reduce heavy coupling with server and clients)
  • They do not use language dependent types or classes in order to understand data and behavior.
Service compatibility is Policy based
  • Policy describes the capabilities of the system.
  • Depending on policies the service can degrade to match the service for the client.


5) Why we cannot say Web Services are Policy based?

Because web services are lack of Policy based service compatibility.

6) WCF over WebServise Advantage

In a WebService
It can only be server with HTTP communication channel and SOAP message. (disadvantage)
but in WCF you server with different channels.(ex Remoting,ASMX, MSMQ...)


 7) What are the core technologies of SOA?
  1. End Point
  2. Contract
  3. Address 
  4. Bindings

8) What is a End Point?(ABC)

 Every service must expose one or more end points by which the service can be available to the client.

 9) What are the important things inside a End Point.(ABC)
  1. Where  (Address)
  2. What (Contract)
  3. How (Binding)
 10) What is a Contract(What)?

Contract is an agreement between two or more parties.
It defines the protocol(set of rules) how client should communicate with your service.
Technically it describes parameters and return values for a method.

11) What is a Address(Where)?

An Address indicates where we can find this service.
Address is a URL which points to the location of the service.


12) What is Binding(How)?

Bindings determine how this end point can be accessed.
It determines how communications is done.ex:(SOAP over HTTP or BINARY over TCP)
So for each of these communications medium two bindings will be created.


13) Summery of Client Connect to a Web Service.

Client can sending requests
    on ADDRESS :"www.Address.com"
    BINDING : using HTTP
    and adhearing to CONTACT : "InterfaceName" interface

14) Which specifications does WCF follow?

WCF supports specifications defined by WS-* specifications.

15) What is the meaning of WS-* specifications?

WS-* specifications are defined together by Microsoft, IBM, SUN and many other big companies so that they can expose there service through a common protocol

16) What are the WS-* specifications?
Need to know what WS-* specification are supported by WCF and its advantages with respect to interacting with other languages.

 Messaging (WS-Addressing):- 
  • SOAP is the fundamental protocol for web services.
  • WSAddressing add extra things to SOAP headers to optimize the performance.
  • It is called as MTOM ( Message Transmission Optimization Mechanism).
  • It uses SOAP messages in XML-Binary formant using XML optimized packaging (XOP) to improve the performance. 
Security (WS-Security, WS-Trust and WS-SecureConversation):- 
  • All the three WS- define authentication, security, data integrity and privacy features for a service.
     
Reliability (WS-ReliableMessaging):- 
  • This specification ensures end-to-end communication.

Transactions (WS-Coordination and WS-AtomicTransaction):-
  • These two specifications enables transaction with SOAP messages.

Metadata (WS-Policy and WS-Metadataexchange):- 
  • WSDL is a implementation of WSMetadataExchange protocol. 
  • WS-Policy defines more dynamic features of a service which can not be expressed by WSDL.


16) What are the main Components of WCF?

Needs to define 3 main components in WCF. 

1. Service Class
2. Hosting Environment
3. End Point
  


17) What is a Service Class/Interface?

The class/interface which has to be exposed to the external client.

Use "ServiceContract" attribute to mark it as the service class/interface.


18) What is a Service Contract attribute?

It define which application interface will be exposed as a interface.

19) Reason to use an Interface as a Service over a Class?

It’s not essential that you need to use an interface you can also use a simple class and mark it as Service

but interface represent a contract and do not have implementation. (very higher level of abstraction.)

It is a good design practice to use a interface as a service.

20) What is a Operation Contract  attribute and Why we use it?

It dictates what methods should be exposed to the external client using the service.

21)What is a Data Contact attribute and Why we use it?

In all the method calls from the service class will involve some kind of a data transfer between client and server.

This attribute defines defines which type of complex data will be exchanged between client and server.

and most importantly it determine which parameters to be serialized.

22) Types that need to mark with Data Contract?

Note: - In interviews need to say that Data Contract define how the
data will be serialized during transmission.



When we using simple data types(int,bool,etc...), it is not necessary to mark them with the data contract attribute

Because we can always find matching types on the client machine.

But for complex data types we need to define this attribute.

This Data Contract defines how this data will be passed during the transmission.(How data serialized and transmit)   

 23) What namespace is used to with Data Contract?

As data contract are all about serialization you need to import System.Runtime.Serialization
name space.


24) Main things behind Hosting a WCF service?

  • Config file 
  • Hosting code is start-up.  
25) What are the various ways of hosting a WCF service?
  • Self Hosting
  • Host in application domain or process provided by IIS.
  • Host in application domain and process provided by WAS(Windows Activation Server)

26) Self Hosting

 Use App.config file

In the configuration section in App.config file

add a new section <system.serviceModel

(it has the endpoint tag- where is the service,what the contact of the service is and how do we communicate with the service


27) What are the advantages of hosting WCF in IIS?
  • Automation activation
  • Process Recycling
(When the browser disconnects the worker process stops and you loose all information. 
IIS also restarts theworker process. By default the worker process is recycled at around 120 minutes. So why does IIS recycle. By restarting the worker process it ensures any bad code or memory leak
do not cause issue to the whole system.)


 
 28) What is the difference between WCF and Web Service?

Web Service can be only invoke by HTTP.
WCF/Service can be invoked by any protocol and any transport type.


Web Services are not flexible.
WCF/ Services are flexible.(can add a new version by exposing a new end point so service are agile and very practicle)

29) What are different bindings supported by WCF?

You can use pre-defined bindngs and customer bindings in WCF.

 BasicHttpBinding:
  • Use SOAP over HTTP.
  • Can use HTTPS.
  • Can configure to send data in plain text or in optimized form like MTOM. 
WsHttpBinding:
  • Use SOAP over HTTP.
  • Same like BasicHttpBinding.
  • Supports Reliable message transfer( WS- ReliableMessaging),Security (WS-Security) and Transactions ( WS-AtomicTransaction)    

 NetTcpBinding:
  • Sends binary encoded SOAP.
  • Support Reliable message transfer, Security and Transactions directly over TCP.
  • Disadvantage : Client and Server should be made in .NET Language.
 NetNamedPipesBinding:
  • Sends binary encoded SOAP over named pipes.
  • Only usable for WCF- to- WCF communication between processes on the same Windows based machine. 
NetMsmqBinding:
  • Sends binary encode SOAP over MSMQ.
  • Can only be used for WCF-to-WCF communication.










Sunday, August 25, 2013

ASP.NET Important Questions

1. What is event bubbling?

As the child control send events to parent it is termed as event bubbling.

Explanation.
Server controls like Data grid, Data List, and Repeater can have other child controls inside them.

Example Data Grid can have combo box inside data grid.

These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a data grid, data list, repeater),

which passed to the page as “ItemCommand” event.

2.How many types of validation controls are provided by ASP.NET?

There are six main types of validation controls:-

1.RequiredFieldValidator
checks - control have any value.(control should not be empty.)

2.RangeValidator
checks-  value in validated control is in that specific range. ( TextBox Value < eight lengths).

3.CompareValidator
checks - value in controls should match some specific value. (Textbox TxtPie should be equal to 3.14.)

4. RegularExpressionValidator
control value should match with a specific regular expression.

5. CustomValidator
It is used to define User Defined validation.

6. Validation Summary
It displays summary of all current validation errors on an ASP.NET page.

Note: - It is rare that some one will ask step by step all the validation controls. Rather they will ask for what type of validation which validator will be used. Example in one of the interviews i was asked how will you display summary of all errors in the validation control...just uttered one word Validation summary.


3.Explain “AutoPostBack”?

If we want the control to automatically post back in case of any event, we will need to check this attribute as true

4. Enable automatic paging in Data Grid?

Following are the points to be done in order to enable paging in Data grid:-
• Set the “Allow Paging” to true.
• In PageIndexChanged event set the current page index clicked.



5. What is the difference between “Web.config” and “Machine.Config”?


Web.config” files apply settings to each web application, while “Machine.config” file apply settings to all ASP.NET applications.

6. What is a SESSION and APPLICATION object?

Session object store information between HTTP requests for a particular user,

while application object are global across users.


7. How do we assign page specific attributes?

Page attributes are specified using the @Page directive.

8. What is the use of @ Register directives?

@Register directive informs the compiler of any custom server control added to the page.

9.How can we create custom controls in ASP.NET and use of @ Register directive?

User controls are created using .ASCX in ASP.NET.

After .ASCX file is created you need to two things in order that the ASCX can be used in project:.

Register the ASCX control in page using the <%@ Register directive.

<%@ Register tag prefix="Accounting" Tag name="footer" Src="Footer.ascx" %>

• Now to use the above accounting footer in page you can use the below directive.

<Accounting: footer runat="server" />


9.What is .NET Reflection?

.NET Framework's Reflection API allows you to fetch type (assembly) information at runtime programmatically.

We can also achieve late binding by using .NET Reflection.

It enables you to use code that is not available at compile time.

.NET Reflection allows an application to collect information about itself and also to manipulate on itself.

It can be used effectively to find all types in an assembly and/or dynamically invoke methods in an assembly.

Using Reflection, you can get any kind of information which you can see in a class viewer; for example, information on the methods, properties, fields, and events of an object.

The System.Reflection namespace and the System.Type class plays a very important role in .NET Reflection. These two work together and allow you to reflect over many other aspects of a type.



 10. What is "Late Binding/dynamic invocation"?

Late binding is a powerful technology in .NET Reflection which allows you to create an instance of a given type and invoke its members at runtime without having compile-time knowledge of its existence;.

This technique is useful only when working with an object which is not available at compile time.

 It is very important to take the right decision when to call and use and when not to use this because of performance issues.

Using this technique has an impact on the performance of your application.



 10. What is  JIT? What is NGEN? What are limitations and benefits of each? 

JIT stands for Just in time compiler it compiles code into native code to execute by processor in three different techniques.

 It compiles code just before code required to be run which makes execution little slow (depends)


so to avoid that we use NGEN

 which converts IL into native code like JIT but during deployment.

 It comes with large image which also includes that codes compiled version which is not being calling frequently.



11. Why do you use the App_Code folder in ASP.NET?

The App_Code folder is automatically present in the project.


 It stores the files, such as classes, typed data set, text files, and reports

Only one dll is created for the complete folder, irrespective of how many files it contains.

12. What is an ASP.NET Web Form?

ASP.NET Web forms are designed to use controls and features that are almost as powerful as the ones used with Windows forms, and so they are called as Web forms.


The Web form uses a server-side control that are executed on the server and are rendered as HTML on the client. 

13. What is Query String? What are its advantages and limitations?

It helps in sending the page information to the server.

Advantages:

    Every browser works with this and does not require server resources and processing power.

Limitations:

    Limited No of Characters : since it is used in the URL.
    Security Threat : info visible to user in the URL.


14. What is the difference between authentication and authorization?

Authentication verifies the identity of a user .


Authorization is a process where you can check whether or not the identity has access rights to the system. 
( procedure of granting access of particular resources)

15. Which ASP.NET objects encapsulate the state of the client and the browser?
The Session object encapsulates the state of the client and browser.


16. Differentiate globalization and localization.

The globalization is a technique to 

              identify the specific part of a Web application
              that is different for different languages 
              and make separate that portion from the core of the Web application.

 The localization is a procedure of 
              configuring a Web application to be supported for a specific language or locale. 


Which namespaces are necessary to create a localized application?

The System.Globalization and System.Resources namespaces are essential to develop a localized application.



17. Which method has been introduced in ASP.NET 4.0 to redirect a page permanently?
 
RedirectPermanent("/path/Name.aspx");


 this Performs a permanent redirection from a requested URL to a specified URL.


18. What is the difference between the Response.Write() and Response.Output.Write() methods?

Response.Write() method allows you to write the normal output; 

Response.Output.Write() method allows you to write the formatted output. 

19. What is the default timeout for a Cookie?

 30 minutes.

20. What are the events that happen when a client requests an ASP.NET page from IIS server?

  1.     User requests for an application resource.
  2.     The integrated request-processing pipeline receives the first user request.
  3.     Response objects are created for each user request.
  4.     An object of the HttpApplication class is created and allocated to the Request object.
  5.     The HttpApplication class processes the user request. 
21. Cookies.
 
How Cookies work.
 

The server tells the browser to put some files in a cookie, and the client then sends all the cookies for the domain in each request. 

Large Cookies affect the network traffic.

What is a Cookie? Where is it used in ASP.NET?

Cookie is a lightweight executable program, which the server posts to client machines.

Cookies store the identity of a user at the first visit of the Web site and validate them later on the next visits for their authenticity.

The values of a cookie can be transferred between the user's request and the server's response.

Explain the cookie less session and its working.

ASP.NET manages the session state in the same process that processes the request and does not create a cookie. It is known as a cookie less session.

 If cookies are not available, a session is tracked by adding a session identifier to the URL.

The cookie less session is enabled using the following code snippet:
 <sessionState cookieless="true" />

 How many types of Cookies are available in ASP.NET?

There are two types of Cookies available in ASP.NET:

  • Session Cookie - Resides on the client machine for a single session until the user does not log out.
  • Persistent Cookie - Resides on a user's machine for a period specified for its expiry, such as 10 days, one month, and never.
The user can set this period manually.
22. What are the event handlers that can be included in the Global.asax file?
Important event handlers:

  •     Application_Start
  •     Application_End
  •     Application_Error
  •     Session_Start 
  •     Session_End   
 23. What is the difference between page-level caching and fragment caching?

Page-level caching, an entire Web page is cached; 

Fragment caching, a part of the Web page, such as a user control added to the Web page, is cached. 

24. Make a list of all templates of the Repeater control. 
Contains following templates:
  1.     ItemTemplate
  2.     AlternatingltemTemplate
  3.     SeparatorTemplate
  4.     HeaderTemplate
  5.     FooterTemplate  
25. What is State Management? How many ways are there to maintain a state in .NET?

State management is used to store information requests.

The state management is used to trace the information or data that affect the state of the applications.

There are two ways to maintain a state in .NET, Client-Based state management and Server-Based state management.

Client-Based state management:

  • View State
  • Hidden Fields
  • Cookies
  • Query Strings
  • Control State
Server-Based state management:

  • Application State
  • Session State
  • Profile Properties 

26. What are the major built-in objects in ASP.NET?

The major built-in objects in ASP.NET are as follows:

  1.     Application
  2.     Request
  3.     Response
  4.     Server
  5.     Session
  6.     Context
  7.     Trace  
27. Why do we need nested master pages in a Web site?

When we have several hierarchical levels in a Web site, then we use nested master pages in the Web site.




28. What is the appSettings Section in the web.config file?

The web.config file sets the configuration for a Web project.

The appSettings block in configuration file sets the user-defined values for the whole application.




29. Which data type does the RangeValidator control support?

The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.



30. Difference between HTML and Web server controls?
HTML controls are client-side controls; therefore, all the validations for HTML controls are performed at the client side.

Web server controls are server-side controls; therefore, all the validations for Web server controls are performed at the server side.

31.  What do you understand by the culture?

The culture denotes a combination of a language and optionally a region or a country.

The contents of a Web page of a multilingual Web site are changed according to the culture defined in the operating system of the user accessing the Web page.

What are the Culture and UICulture values?

Culture value determines the functions, such as Date and Currency, which are used to format data and numbers in a Web page.

 UICulture value determines the resources, such as strings or images, which are loaded for a Web page in a Web application.

What do you mean by a neutral culture?

When you specify a language but do not specify the associated country through a culture.


32. What is the use of the Global.asax file?The Global.asax file executes application-level events and sets application-level variables.


ASP.NET Life Cycle Interview Questions and Answers

1. What’ is the sequence in which ASP.NET events are processed?

Following is the sequence in which the events occur:-
• Page_Init.
• Page Load.
• Control events
• Page- Unload event.

2. Difference Between Page Init and Page Load events?

Page_init event only occurs when first time the page is started, but Page Load occurs in subsequent request of the page.

3. In which event are the controls fully loaded?


Page load event guarantees that all controls are fully loaded.
Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event.

4. How can we identify that the Page is Post Back?

Page object has an IsPostBack” property, which can be checked to know that is the page posted back.


5. How do we ensure view state is not tampered?


Using the @Page directive and setting EnableViewState’ property to True.

6. What is the use of Smart Navigation property?

It’s a feature provided by ASP. NET to prevent flickering and redrawing when the page is posted back.
 but this is only supported for IE browser.

7. Where is View State information stored?

In HTML Hidden Fields.

8. In which event are the controls fully loaded?

Page load event guarantees that all controls are fully loaded. 

Controls are also accessed in Page_Init events

but you will see that view state is not fully loaded during this event

9. What is the lifespan for items stored in ViewState?

Lifetime of the current page expires including the postbacks to the same page.

 10. What are the advantages of the code-behind feature?
  •     Makes code easy to understand and debug by separating application logic from HTML tags
  •     Provides the isolation of effort between graphic designers and software engineers
  •     Removes the problems of browser incompatibility by providing code files to exist on the Web server and supporting Web pages to be compiled on demand. 
 11. In which event are the controls fully loaded? 

Page load event guarantees that all controls are fully loaded

Controls are also accessed in Page_Init events but you will see that view state is not fully loaded.

12. What is the lifespan for items stored in ViewState? 

Lifetime of the current page expires including the postbacks to the same page. 

13. What is ViewState?
 

ViewState - store the value of a page and its controls just before posting the page. 

Once the page is posted, the first task by the page processing is to restore the ViewState to get the values of the controls. 

 14.Describe the complete Life Cycle of a Web page.When we execute a Web page, it passes from the following stages, which are collectively known as Web page lifecycle:
  1.Page request -
 


ASP.NET makes sure the page either parsed or compiled and a cached version of the page can be sent in response
 
   2.Start -
 


Sets the Request and Response page properties and the page check the page request is either a postback or a new request

   3. Page Initialization - 

Page initialize and the control's Unique Id property are set.
 
    4.Load -
 


If the request is postback
      control properties are loaded without loading the view state and control state 

otherwise 
     loads the view state
 
    5.Validation -
 


The controls are validated
 
    6.Postback event handling -


If the request is a postback, handles the event
 
    7.Rendering -
 


Page invokes the Render method to each control for return the output

   8. Unload -

Page is completely rendered and sent to the client, the page is unloaded. 




15.What events are fired when a page loads?
The following events fire when a page loads:

    Init() - Fires when the page is initializing.
    LoadViewState() - Fires when the view state is loading.
    LoadPostData() - Fires when the postback data is processing.
    Load() - Fires when the page is loading.
    PreRender() - Fires at the brief moment before the page is displayed to the user as HTML.
    Unload() - Fires when the page is destroying the instances of server controls.






Thursday, August 22, 2013

Wednesday, August 21, 2013

LINQ


1.What is ORM?

ORM stands for Object-Relational Mapping. 

Sometimes it is called O/RM, or O/R mapping. 

It is a programming technique that contains a set of classes that map relational database entities to objects in a specific programming language.

ORM, each database is represented by an ORM context object in the specific programming language, and database entities such as tables are represented by classes, with relationships between these classes.

The ORM is responsible for the mappings and the connections between these classes and the database. 

The application only needs to deal with these classes, instead of with the physical database. 

The application does not need to worry about 

  • how to connect to the database,
  •  how to construct the SQL statements, 
  • how to use the proper locking mechanism to ensure concurrency,
  •  how to handle distributed transactions. 

These databases-related activities are handled by the ORM.

2.What is ODBC?


It was developed to unify all of the communication protocols for various RDBMSs. 

ODBC was designed to be independent of programming languages, database systems, and Operating Systems. 

So with ODBC, an application could communicate with different RDBMSs by using the same code, simply by replacing the underlying ODBC drivers.


3. Ways of accessing a Database from an Application



There are some other mechanisms to access a database from an application, such as JDBC and ADO.NET. However, to keep the diagram simple, they have not been shown here.
Pic01.jpg




4. LINQ to SQL


4.1 What is LINQ to SQL

Component of the .NET Framework version 3.5

Data model of a relational database is mapped to an object model expressed in the programming language .

4.2 How it Works?

When the application runs,
                             LINQ to SQL translates the ->
                                             language-integrated queries in the object model->
                                                                 into SQL and sends them to the database for execution.
When the database returns the results, 
                             LINQ to SQL translates them 
                                             back to objects that you can work with in your own programming language.

4.3 It Supports

  1. Transactions, 
  2. Views,
  3. Stored Procedures,
  4. User-defined functions
  5. Provide easy way to integrate data validation and business logic rules into your data model.
  6. Supports single table inheritance in the object model.

4.4 What are the existing .NET ORM Products

Open Source products 

  • NHibernate, 
  • NPersist
Commercial products 
  • LLBLGen 
  • WilsonORMapper
LINQ to SQL is one of Microsoft's new ORM products to compete with many existing .NET ORM products.

4.5 LINQ to SQL - Advantages over other ORM products

It is designed and built specifically for .NET and SQL Server

It has many advantages over other ORM products

  • Can use LINQ features 
  • It fully supports SQL Server Stored Procedures
  • All the relationships (foreign keys) for all tables, and the fields of each table just become properties of its corresponding object.
  • Intellisense popup when you type in an entity (table) name
  • All of the fields and the query results are strongly typed,(get a compiling error instead of a runtime error)

4.6 LINQ to SQL -What is Happening inside. 

In LINQ to SQL, ADO.NET SqlClient adapters are used to communicate with real SQL Server databases.

The usage of LINQ to SQL in a .NET application:
Pic02.jpg



5. Comparing LINQ to SQL  with LINQ to Objects

Lets look at the relationships between LINQ to SQL and LINQ to Objects(use LINQ to query in-memory objects).


Some key Differences
  • LINQ to SQL needs a Data Context object. (bridge between LINQ and the database)
  • LINQ to Objects doesn’t need any intermediate LINQ provider or API.
  • --------
  • LINQ to SQL returns data of type IQueryable<T> (This is a derived type from IEnumerable<T> interface.)
  • LINQ to Objects returns data of typeIEnumerable<T>
  • --------
  • LINQ to SQL is translated to SQL by way of Expression Trees.(allow them to be evaluated as a single unit and translated to the appropriate and optimal SQL statements)
  • LINQ to Objects does not need to be translated.
  • --------
  • LINQ to SQL is translated to SQL calls and executed on the specified database.
  • LINQ to Objects is executed in the local machine memory.

Some key Similarities 

  • All use the same SQL like syntax and share the same groups of standard query operators
  • From a language syntax point, working with a database is the same as working with in-memory objects.


6. LINQ to Entities 

6.1 Let’s first see what Entity Framework is

ADO.NET Entity Framework (EF) was first released with Visual Studio 2008 and .NET Framework 3.5 Service Pack 1. 

Many people view EF as just another ORM product from Microsoft, though by design it is supposed to be much more powerful than just an ORM tool.


6.2 What is inside Entity Framework 

With Entity Framework, developers work with a Conceptual Data Model(CDM), and Entity Data Model(EDM),instead of the underlying databases.


  • Conceptual Data Model(CDM) is expressed in the Conceptual Schema Definition Language (CSDL).
  • Data Base(Actual Storage Model) is expressed in the Storage Schema Definition Language (SSDL).
  • Mapping in between CDM and Data Base is expressed in the Mapping Schema Language (MSL).

A new data-access provider(Object Services Model)EntityClient Data Provider, and ADO.NET data providers are still being used to communicate with the databases. 

The diagram below, which has been taken from the July 2008 issue of the MSDN Magazine, shows the architectures of the Entity Framework.
Pic03.jpg

6.3 What we can see from the above Diagram


We can see that LINQ is one of the query languages that can be used to query against Entity Framework Entities.

6.4 LINQ to Entities Advantages

LINQ to Entities allows to create 
                                                flexible, 
                                                strongly typed queries 
                                                              against the Entity Data Model (EDM)
 by using LINQ expressions and the LINQ standard query operators. 

It is the same as what LINQ to SQL can do, though LINQ to Entities supports more features than LINQ to SQL,

  •  like multiple-table inheritance, 
  •  it supports many other mainstream RDBMS databases besides Microsoft SQL Server, like Oracle, DB2, and MySQL.

6.5 How it Works

  • LINQ to Entities applications work against a conceptual data model (EDM). 
  • All mappings between the languages and the databases go through the new Entity Client Mapping provider
  • The application no longer connects directly to a database.
  • This means that you can no longer use the native database query language; not only will the database not understand the EDM model, but also current database query languages do not have the constructs required to deal with the elements introduced by the EDM such as inheritance, relationships, complex-types, etc.


6.6. Comparing LINQ to SQL  with LINQ to Entities

Some key Advantages

LINQ to SQL enables developers to experience the LINQ programming model directly over an existing database schema.( allows developers to generate .NET classes that represent data. Rather than mapping to a conceptual data model) - These generated classes map directly to database tables, views, Stored Procedures, and user defined functions. 

Using LINQ to SQL, developers can write code directly against the storage schema using the same LINQ programming pattern as previously described for in-memory collections, Entities, or the DataSet, as well as other data sources such as XML.

Some key Differences

LINQ to SQL has some limitations, mainly because of its direct mapping against the physical relational storage schema. For example, you can’t map two different database entities into one single C# or VB object, and underlying database schema changes might require significant client application changes.

The table below lists some supported features by these two data access methodologies:
FeaturesLINQ to SQLLINQ to Entities
Conceptual Data ModelNoYes
Storage SchemaNoYes
Mapping SchemaNoYes
New Data Access ProviderNoYes
Non-SQL Server Database SupportNoYes
Direct Database ConnectionYesNo
Language Extensions SupportYesYes
Stored ProceduresYesYes
Single-table InheritanceYesYes
Multiple-table InheritanceNoYes
Single Entity from Multiple TablesNoYes
Lazy Loading SupportYesYes



7.0 Deferred Execution


One important thing to remember when working with LINQ to SQL is the deferred execution of LINQ.

The standard query operators differ in the timing of their execution, depending on whether they return a singleton value or a sequence of values.

  • Excute Immediately -  return a singleton value (for example, Average and Sum) execute immediately. 
  • Not Excuted Immediately- Methods that return a sequence and return an enumerable object.
IEnumerable<T> Interface.

  • Methods that operate on in-memory collections and extend this inteface will return enumerable object.
  • When that  enumerable object is enumerated, the logic of the query operator is employed and the query results are returned.

IQueryable<T> Interface.

  • Methods that extend this interface do not implement any querying behavior, but build an expression tree that represents the query to be performed. 
  • The query processing is handled by the source IQueryable object.