We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Thursday, March 26, 2015

Interview questions and answers of LINQ


1.) What is LINQ ?

LINQ stands for language Integrated query.It was introduced as a new component of .NET Framework 3.0 .Its syntax is similar to Structure Query Language (SQL).Linq is a programming model that is used to provide a consistent method to obtain and manipulate the data.It can easily perform some query operations from various data sources like SQL,XML,Web services ,Dataset etc.LINQ Query performs additional operations such as sorting ,ordering and grouping the retrieved data.

2.) Why does we use LINQ Query?

There are following reasons to use LINQ Query as given below:-
LINQ Provide full type checking at compile time.
LINQ is used with c# and vb .net in .NET Framework.
LINQ Provides uniform programming models (use common query for different data sources).

3.) What are the various data sources used with LINQ?

LINQ to Object
LINQ to ADO.NET
LINQ to XML

4.) Which Namespace is used for LINQ?

Using System.LINQ.

5.) What are the advantage of LINQ?

There are some advantages of LINQ Query.
LINQ Provides uniform programming model(use common query for different data sources )
LINQ supports some powerful features like ordering ,filtering and grouping.
It provides short codes.
Linq query can be used again and again.
LINQ helps to avoid Runtime errors.
LINQ query uses .NET Developers for Debugging purpose.

6.) What are the disadvantage of LINQ?

There are some disadvantage of LINQ.
It is more complex than SQL query.
Sql query is good for writing the complex query.
LINQ query performance is not good as sql query.
We can't implement some features with linq like sql(cached feature of Stored procedure in sql).

7.) What are three basic steps to execute the LINQ query?

Obtain the data source that can be either sql database or an XML File.
Create the query
Execute the Linq query

8.) What is Extension Methods in LINQ query?

The Extension Method, in .NET Framework allow you to add methods to existing types without creating a new derived type.Means You can easily extend the functionality of existing method.This is done by re-compiling and modifying the original type.
The extension Method takes parameters in which first parameter defines the types that it extends.A class that defines the Linq extension method is called Enumerable class.

9.) What are the rules for extension methods?

Method must be static
Method must be declared in static class.
Method must be taken the parameter

10.) What is difference between Extension method and Normal Method?

In an Extension Method requires this keyword with the first parameter but in Normal method don't like that.
The Extension Method can not access the private members of the type that it extends.

11. ) What is Anonymous Methods?

Anonymous method allow you to handle an event rather having a separate event handler. Suppose you want to display some message to users at a click of a button ,ypu can handle it in a standard way with a delegate and event handler or you can also perform this action using anonymous method.
There are some points about anonymous method as given below:-
You can not have a jump statement,Break,Go to and continue in an anonymous method.
If your program contains same functionality more than once ,you should not use anonymous method.
You should also not use an unsafe code inside an anonymous method.

12. ) What are benifits of Anonymous Methods?

Anonymous Methods helps to reduce the codes .
No need to define any static event handlers in anonymous method.

13. ) What is Lambda Expression?

Lambda Expression is the extension of the anonymous method.In .NET Framework 3.5 , a new syntax is introduce in anonymous method that is called Lambda expression. Lambda Expression is an anonymous function that can contain expression and statement to create delegates or expression tree types.It uses the Lambda operator (=>).
Ex.
(Input parameter) => expression;
The Left had side of the Lambda operator specifies the Expression or the statement.
Here parentheses are optional if Lambda Expression has only one parameter.
If Lambda Expression contains more than one parameter then parentheses and commas (') are required otherwise program will give error.

14. ) What are the benefits of Lambda Expression?

There are some benefits of Lambda Expression in Linq as given below:-
The Lambda Expression allows you to declare your method code inline instead of with the delegate function.
It has more concise syntax to achieve same goal.
The Lambda Expression are very helpful in writing Linq query expression with a very compact and concise way.

15. ) What is Lambda VS Anonymous Method?

The Lambda Expression is almost similar to anonymous method which was introduced with .NET 2.0.
The Lambda Expression provides a more concise and functional syntax for writing the anonymous method.
There are no basic Difference between them.Means Lambda Expression is an anonymous function.
In Lambda Expression ,syntax elements are not required,which is automatically managed by the compiler.

16. ) What are different Methods to write LINQ Query?

Query Syntax
Method Syntax
Mixed Syntax

17. ) What are quantifiers in Linq?

There are some quantifiers in Linq as given below:-
All ( )
Contains ( )
Any ( )
SequenceEqual()

18.) What are different Aggregate operators used in Linq?

There are some aggregate operators used in Linq as given below:-
Aggregate
Average
Count
LongCount
Min
Max
Sum

19.) What are different Join operators used in Linq?

Join
GroupJoin

20.) What are different Ordering operators used in Linq?

OrderBy
OrderByDescending
ThenBy
ThenByDescending
Reverse

21.) What are Standard Query operators in LINQ ?

The standard query operators are the methods that form the LINQ pattern.These operators provide query capabilities including filtering ,projection,aggregation and sorting.The standard query operator in LINQ is an application programming interface (API) that enables querying of any .NET array or collection.
There are two set of standard query operators in LINQ.
Operator on objects of the type IEnumerables
Operator on objects of the type IQueryable

22.) What are the List of Standard Query operators in LINQ ?

Filtering operator
Projection operator
Sorting Operator
Join Operator
Grouping operator
Quantifier Operator
Partitioning operator
Set operator
Element operator
Aggregate operator
Conversion operator
Generation operator

23.) What is filtering operators in LINQ ?

Filtering operators contains only those element that satisfy a specified given condition. 'WHERE' Clause in C# or VB is used as filtering operator in LINQ.
Syntax:-
public static IEnumerable WHERE
(this IEnumerable source,
Function predicate);

25.) What methods are used in projection operators ?

Select()
Selectmany()

26.) What is sorting operators in LINQ?

The sorting operator in LINQ arranges the elements of a sequence based on one or more attributes.It changes the order of elements of sequence returned by the query.
Syntax:-
public static orderedsequenceorderBy/orderByDescending
(this IEnumerable source,
Function keyselector);

27.) What clauses are used in sorting operators ?

OrderBy
orderbydescending
orderbyascending

28.) What is Join operators in LINQ ?

The Join operators in LINQ are used to join object in one data source with objects that share a common attribute in another datasource.
Syntax:-
public static IEnumerableJoin
(this IEnumerable outer,
IEnumerable inner,
Function outerKeyselector,
Function innerKeyselector,
Function resultselector);

29.) What is LINQPad ?

LINQPad is a popular tool for testing LINQ Queries.It allows you to execute LINQ queries ,c#,vb, sql statement etc.This is developed by Joseph Albahari.

30.) What is Grouping Operator in LINQ ?

Grouping operator is used to put data into groups so that the elements in each group share a common attribute.
Syntax:-
public static IEnumerable>GroupBy
(Me IEnumerable source,
Function KeySelector);

32.) What are set operators in LINQ ?

The set operators in LING refer to the query operators that produce a result set.The result set based on the presence or absence of the equivalent elements that are present within the same clauses used in set operators.
Distinct
Union
Intersect
Except
Syntax:-
public static IEnumerable Distinct
(this IEquatable source1, IEquatable source2);

33.) What are Element operators used in LINQ ?

The element operators in LINQ return just one element.
There are some clauses used with LINQ query as given below.
ElementAt :- This clause returns the element at a specified index in a collection.
First :-This clause returns the first element of the collection.It returns a default value if there is no such element.
FirstorDefault :- This clause returns the first element of a collection or the first element that satisfies a given condition.It returns default value if there is no such element.
Last :- This clause returns the last element of the collection or the last element or the last element that satisfies the given condition.
LastorDefault :- This clause returns the last element that satisfies the given condition.It returns a default value if there is no matching element.
Single :- This clause returns the only element of the collection that satisfies given condition.
Single or Default :- This clause returns the only element of the collection that satisfies the given condition.
Syntax:-
public static S FirstorDefault
(this IEnumerable source,
Function predicate);

34.) What are aggregate operators in LINQ ?

The aggregate operators compute a single value from a collection.
Aggregate
Average
Count
Long Count
Max
Min
Sum
Syntax:-
public static int count
(this IEnumerable source,
Function predicate);

35.) What are conversion operators in LINQ ?

The conversion operators convert a collection to an array .A conversion operator changes the type of input object.
There are different conversion operators as given below:-
ToSequence :- This clause simply returns the source argument by changing it to the IEnumerable Collection.
ToArray:- This clause enumerates the source sequence and returns an array containing the elements of the sequence.
ToDictionary :-This clause lists the source sequence and evaluates the keyselection and elementselector functions for each element to produce the element key and value of the source sequence.
ToLookup:- This clause implement one to many dictionary that maps te key to the sequence of value.
OfType:- This clause allocates and returns enumerable object that captures the source argument.
Cast :- This clause allocates and returns an enumerable object that captures the source argument.
Syntax:-

36.) What are Generation operators in LINQ ?

The Generation operators help in creating a new sequence of values.
There are some generation operators used in LINQ as given below:-
Empty :- This clause refers to an empty collection.
Range:- This clause generates a collection that contains a sequence of numbers.
Repeat :- This clause generates a collection that contains at least one repeated value.
Syntax:-
public static IEnumerable Range
(int start, int count);

37.) What is LINQ to Object and its benefits ?

LINQ to Object refers to the use of LINQ queries with any IEnumerable collection directly ,without the use of any intermediate LINQ provider or Interface.
There are some benefits of LINQ to Object as given below:-
It helps in filter multiple conditions as they more concise and readable.
It gets easily ported to other data sources with little or no modification.
It provides powerful filtering ,ordering and grouping capabilities with the use of minimum application code.

38.) What is LINQPad ?

The LINQPad supports LINQ to SQL ,Entity Framework ,WCF Services and others Technology also.

39.) What is LINQ Insight ?

We can use LINQPad as a LINQ Insight. LINQ Insight is an alternative of LINQPad. It is helpful to Viewing of SQL ,LINQ to Entities, LINQ to SQL ,LINQ to NHibernate etc.

40.) What is LINQ Providers ?

A LINQ Provider is a Library which is used to execute query against data source.

41.) What are the types of LINQ Providers?

There are some types of LINQ Providers as given below:-
LINQ to SQL
LINQ to Objects
LINQ to Data sets
LINQ to XML
LINQ to Entities

42.) Can we use 'having' clause in LINQ like sql?

Yes.

43.) What is extension of file,when we use LINQ to SQL?

.dbml extension

44.) Why do we use string in LINQ?

LINQ is used to query and transform strings and collections of strings.It is useful with semi-structure data in the text file.

45.) Why do we use Reflection concepts in LINQ?

The .NET Framework class library uses the concepts of reflection to examine the meta data in the .NET assembly and create collections of types and members.The System.Reflection namespace is used to use Reflection in LINQ.

46.) What is the concepts of PLINQ query?

A Simple PLINQ query works on a large collection of data.The effect of PLINQ is not visible.

47.) What is ZIP Operator?

The ZIP operators helps in combing two collections into one .It was introduced in LINQ in ASP.NET 4.0. It uses the Zip() method to merge the two sequences which are identical in length into one.
Syntax:-
Public static Parallelquery zip
( this parallelqueryFirst,
this parallelquery Second,funcResultSelector)

48.) What is the use of file Directories in LINQ?

It use the file directory feature to find all the files that have a specified file name extension.
It retrieve the total number of bytes used by all the files in a specified folders and its sub folder.
It use the file info object to retrieve the size of the largest file.
it perform advance grouping and sorting operations on a folder and list of files.

49.) What is LINQ to ADO.NET ?

LINQ to ADO.NET helps you to query on any ado.net object using LINQ programming model.It consists of two separate technologies.
LINQ to Dataset
LINQ to SQL

50.) What is LINQ to XML ?

LINQ to XML is a new way to write and read xml data in .NET Framework .The system.xml.Linq namespace is used for LINQ to XML.
There are some advantage to use LINQ to XML.
It helps to Load xml from files or stream.
It serialize the xml to files and stream.
It is helpful to control in-memory xml tree.
It validate the XML tree using XML Schema Definition (XSD).

No comments: