LINQ Interview Questions and Answers (70) - Page 3

What is Object Relational Designer (0/R Designer)?

NOTE: This is objective type question, Please click question title for correct answer.
On what parameter does the GroupBy clause group the data?

NOTE: This is objective type question, Please click question title for correct answer.
How can you open the O/R Designer?

NOTE: This is objective type question, Please click question title for correct answer.
What are lambda expressions in LINQ?

NOTE: This is objective type question, Please click question title for correct answer.
Name the control that exposes the LINQ features to Web developers through the ASP.NET data-source control architecture

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of SingleOrDefault?

NOTE: This is objective type question, Please click question title for correct answer.
What is the difference between IQueryable and IEnumerable interface?

NOTE: This is objective type question, Please click question title for correct answer.
Difference between XElement and XDocument

NOTE: This is objective type question, Please click question title for correct answer.
How can we handle concurrency in LINQ?

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of SequenceEqual?

The SequenceEqual operator determines whether all elements in two collections are equal and in the same order.
e.g.

using System;

using System.Linq;

class Program
{
static void Main()
{
string[] array1 = { "dot", "net", "perls" };
string[] array2 = { "a", "different", "array" };
string[] array3 = { "dot", "net", "perls" };
string[] array4 = { "DOT", "NET", "PERLS" };

bool a = array1.SequenceEqual(array2);
bool b = array1.SequenceEqual(array3);
bool c = array1.SequenceEqual(array4, StringComparer.OrdinalIgnoreCase);

Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
}
}

Output
False

True
True

What is the purpose of ElementAt?

The ElementAt operator retrieves the element at a given index in the collection.
e.g.

string[] names =

{ "Niladri", "Arina", "Bob","Foo", "Bar" };
Random random = new Random(DateTime.Now.Millisecond);

string name = names.ElementAt(3);

Console.WriteLine("The name chosen is '{0}'.", name);




/*
This code produces the following sample output:

The name chosen at random is 'Foo'.
*/

What is the output of the following query? SELECT EnrollmentDate, COUNT(*) AS StudentCount FROM Person WHERE EnrollmentDate IS NOT NULL

In the below query, we have a table named Person containing EnrollmentDate and so on. This Enrollment column allows nulls while insertion. We are performing the select command based on EnrollmentDate column which is not null. ie, first it checks only for the rows that contain a value in the Enrollment column, then performs GroupBy.
Then it searches for the rows that contains the same EnrollmentDate, counts the number of rows and displays them in the StudentCount column.

Suppose if we have a table like below:

EnrollmentDate Name
01-01-2013 aaaaaaaa
01-05-2013 bbbbb
01-01-2013 ccccccc
01-01-2013 ddddd

Then the ouput will be
EnrollementDate StudentCount
01-01-2013 3
01-05-2013 1
What is the meaning of the following query? Select EnrollmentDate, Count(*) AS StudentCount From TableName GROUPBY EnrollmentDate

The AS clause holds the column name that you want to give.
Hence in the result, the column name for the count will be StudentCount whereas if you dont specify the AS clause then in the result it shows No column name because this column(Count) doe not exist in your database.
What is the output of the following query? var query = from student in students group student by student.Last[0];

In this students in a table name and student is the alias name given to it.
This query is used for grouping the students based on the first letter of their LastName.
Write a program using Linq to create a sequence that contains common first letter from both Product and Customer names?

var productFirstChar = from P in Products
select P.ProductName[0];

var customerFirstChar = from C in Customers
select C.CompanyName[0];

var commonFirstChar = productFirstChar.Intersect(customerFirstChar );
How can we write the Linq query for selecting a set of first authors in the books containing the word 'our' in the title, using local variables?

IEnumerable<Author> firstAuthors = from b in books
let title = b.Title
let authors = b.Authors
where title.Contains("our")
select authors[0];

foreach (Author author in firstAuthors)
Console.WriteLine("Author - {0}, {1}",
author.LastName, author.FirstName);
Tell us about the advantages of LINQ over Stored Procedure?

Debugging – LINQ supports .Net debugger,so we can easily debug a LINQ query using .Net debugger but it is not supported by SQL stored procedure so it is hard to debug the stored procedure.
Deployment – To deploy stored procedure it is necessary to write one more script to run them,while LINQ will complie by a single DLL statement and so the deployment will be simple.
Type Safety - As LINQ supports type safety so errors can be type checked in LINQ queries in compile time.
It is better to use LINQ as it enable us to identify the errors while compilation rather than runtime execution.
Which are the rules apply to a variable scope in lambda expressions?

1). A variable used in lambda expression won't be garbage-collected until the delegate that references that variable is out of the scope.
2). Variables used in a lambda expression won’t be accessible in the parent method.
3). A lambda expression can’t get a ref or out parameter from an containing method.
4). The return statement used in a lambda expression won’t return for the enclosing method.
5). A lambda expression does not support a goto, break or continue statement who point t outer the body.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories