• Register
1,980 points
8 1

1. Explain what is LINQ? Why is it required?

Language Integrated Query or LINQ is the collection of standard query operators which provides query facilities into.NET framework language like C#, VB.NET.

LINQ is required as it bridges the gap between the world of data and world of objects.

2. What do you mean by Query and Sequence operators in LINQ?

The sequence is a collection class on which you want to query. An Element is a single item in the collection class and the class must implement the IEnumerable interface.
Query operators take in the sequence as input, process it and return the new result sequence.


3. Define Extension Methods ?

Extension methods are static functions of a static class. These methods can be invoked similar to the syntax of the instance method. These methods are used when a class needn’t be modified.

4. What are Anonymous data types?

Anonymous types are types that are generated by the compiler upon runtime. We don’t need to specify a name when we create an anonymous type. Only properties names are created and values assigned to them at runtime.
In LINQ, Anonymous types are used to also save intermediate results. However, Anonymous types cannot implement interfaces, specify methods, or define static methods. All defined properties must be initialised and only public fields can be defined.

5. Explain how LINQ is useful than Stored Procedures?

  • Debugging: It is difficult to debug a stored procedure but as LINQ is part of.NET, visual studios debugger can be used to debug the queries
  • Deployment: For stored procedure, additional script should be provided but with LINQ everything gets compiled into single DLL hence deployment becomes easy
  • Type Safety: LINQ is type safe, so queries errors are type checked at compile time

6. List out the three main components of LINQ? Explain what is the extension of the file, when LINQ to SQL is used?

Three main components of LINQ are

  • Standard Query Operators
  • Language Extensions
  • LINQ Providers

The extension of the file used is .dbml

7. What is the Query syntax?

Query syntax is similar to Structured Query Language for the database. It is described within the C# or VB code.

Syntax

  1. from <range variable> in <IEnumerable<T> or IQueryable<T> Collection>  
  2. <specific Query Operators> <lambda expression>  
  3. <select or groupBy operator> <result formation>  

Few important points about Query syntax are as follows.

  • It starts with FROM keyword and ends with SELECT or GROUP BY keyword.
  • It is same as SQL (Structured Query Language) syntax.
  • It uses some different operators like joining, grouping, sorting, filtering operators to construct the desired result.
  • It uses implicitly typed variable to hold the result of the LINQ query.

8. Define different types of LINQ?

The different types of LINQ are as follows.

  • LINQ to Objects
  • LINQ to XML(XLINQ)
  • LINQ to DataSet
  • LINQ to SQL (DLINQ)
  • LINQ to Entities

Apart from the above, there is also a LINQ type named PLINQ, which is Microsoft's parallel LINQ.

9. Differentiate between LINQ and Stored Procedure?

Some significant differences between LINQ and Stored Procedure are as follows -

  • The stored procedure is faster than a LINQ query because they follow a proper (Expected) execution plan.
  • It is easy to avoid run time errors in SQL query than in comparison to a stored procedure.
  • LINQ uses the .NET debugger to allow debugging, which is not in case of stored procedures.
  • LINQ supports multiple databases in contrast to stored procedures.
  • Deployment of LINQ based solution is more comfortable than the deployment of a stored procedure.

10. What is meant by Action in LINQ?

Action refers to the general delegates belonging to the base class library of .NET. We can store only methods with input parameters and void return types in Action. Upto 16 parameters can be specified.

SOURCES :

monsterindia.com

career.guru99.com

javatpoint.com

1,980 points
8 1