Q#1. Explain what is LINQ? Why is it required?
Ans. 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.
Q#2. What do you mean by Query and Sequence operators in LINQ?
Ans. 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.
Q#3. What are the types of LINQ?
Ans. LINQ to Objects
LINQ to XML
LINQ to Dataset
LINQ to SQL
LINQ to Entities
Q#4. Define Extension Methods.
Ans. 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.
Q#5. Explain how LINQ is useful than Stored Procedures?
Ans. 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
Q#6. What are Anonymous data types?
Ans. 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.
Q#7. Explain why SELECT clause comes after FROM clause in LINQ?
Ans. With other programming language and C#, LINQ is used, it requires all the variables to be declared first. “FROM” clause of LINQ query defines the range or conditions to select records. So, FROM clause must appear before SELECT in LINQ.
Q#8. Explain Lambda Expression.
Ans. Lambda expression is a shortcut to writing delegates. Lambda expression is used to write inline functions that can be passed as arguments to a function or returned as arguments from a function.
The syntax of a Lambda expression is:
We specify the input parameters on the left, the lambda operator in the middle and expression or statement block on the right side.
Q#9. Explain what is the use of System.XML.Xlinq.dll?
Ans. System.Data.Dlinq.dll provides the functionality to work with LINQ to SQL
Q#10. What is meant by Action in LINQ?
Ans. 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.