1. What is Quantifiers in reference linq to Dataset?

Quantifier Operators return the Boolean value (either True or false) if some or all the elements in a sequence satisfy a condition,
Mainly two Quantifiers in linq:

Any
All

Examples (vb)

"Any" to determine if any of the words in the array contain the substring

Public Sub ExampleAny()
Dim words() = {"believe", "relief", "receipt", "field"}
Dim iAfterE = words.Any(Function(w) w.Contains("ei"))
Console.WriteLine("There is a word that contains in the
list that contains 'ei': {0}", iAfterE)
End Sub


Result:
There is a word that contains in the list that contains 'ei': True

"All" to return a grouped a list of products only for categories that have all of their products in stock

Public Sub Quantifier_All_Exam()
Dim products = GetProductList()
Dim productGroups = From p In products _
Group p By p.Category Into Group _
Where (Group.All(Function(p) p.UnitsInStock > 0)) _
Select Category, ProductGroup = Group
ObjectDumper.Write(productGroups, 1)
End Sub

2. Why do we use “Contains” method for strings type functions?

Contains method Used to find all matching records From Given string using Matching keywords.
Example-
This Examples returns the Customer Names from Customer tables whose Names have contains “Anders”

Public void LinqToSqlStringUsingContains()
{
Var q = From c In db.Customers _
Where c.ContactName.Contains("Anders") _
Select c
ObjectDumper.Write(q)
}

3. List out the Data Context Functions. Where do we use “SubmitChanges()”?

Create Database ()
Delete database ()
Database Exist ()
Submit Changes ()
Create Query()
Log()
SubmitChanges() - SunbmitChanges Data Context Fuction Used to submit any update to the actual database.

4. Differentiate between Conversion Operator “IEnumerable” and “ToDictionary” of LINQ?

IEnumerable and To Dictionary both are Conversion Operator which are used to solved to conversion type Problems.
“AsEnumerable ” operator simply returns the source sequence as an object of type IEnumerable. This kind of “conversion on the fly” makes it possible to call the general-purpose extension methods over source, even if its type has specific implementations of them
Signature:

public static IEnumerable<T> AsEnumerable<T>
(
this IEnumerable<T> source
);


“ToDictionary ” Conversion Operator is the instance of Dictionary (k,T) . The “keySelector ”predicate identifies the key of each item while “elementSelector ”, if provided, is used to extract each single item.
Key and elementSelector Predicate can be Used in following ways-
Example-

Public void ToDictionatyExample()
{
Var scoreRecords=
{
new {Name = "Alice",Score = 50 },
new {Name = "Bob",Score = 40 },
new {Name = "Cathy", Score = 45}
};
Var scoreRecordsDict = scoreRecords.ToDictionary(sr => sr.Name);
Console.WriteLine("Bob's score: {0}", scoreRecordsDict("Bob"));
}


Result: Bob's score: { Name = Bob, Score = 40 }

5. How can we find Sequence of Items in two different array (same Type) in the same order using linq query?

Public void MatchSequenceLinq()
{
Var wordsA = {"Rahul","ashok","sweta"};
Var wordsB = {"rahul","ashok","sweta"};
var match = wordsA.SequenceEqual(wordsB);
Console.WriteLine("The sequences match: {0}", match);
}

6. What is “OfType” in linq?

public void TypeofExa()
{
Var numbers = {null,1.0,"two", 3,"four",5,"six",7.0 };
var doubles = from n in numbers where n is doublen;
Console.WriteLine("Numbers stored as doubles:");
foreach (object d in doubles)
{
Console.WriteLine(d);
}
}


Output:
Numbers stored as doubles:
1
7

7. How can you find average of student marks from student tables (Columns are StudentID, Marks)?

(C#)

Public void LinqToSqlAverage()
{
var query = (from p in db. student. Marks).Average();
Console.WriteLine(q);
}

8. Write a Program for Concat to create one sequence of Data Rows that contains DataTabless Data Rows, one after the other?

(C#)

Public void Datasetlinq()
{
var numbersA = TestDS.Tables("NumbersA").AsEnumerable();
var numbersB = TestDS.Tables("NumbersB").AsEnumerable();
var allNumbers = numbersA.Concat(numbersB);
Console.WriteLine("All numbers from both arrays:");
foreach (object n_loopVariable in allNumbers)
{
n = n_loopVariable;
Console.WriteLine(n["number"]);
}
}

9. Write a Program using Skip and Take operators. How can it beneficial for bulky data accessing on page?

“skip” and “take” Operator used for Paging. Suppose we have Customer table of 100 records. To find 10 records by skipping the first 50 records from customer table-

Public void Pagingdatasource ()
{
Var Query = from CusDetails in db.customer skip (50) Take (10)
ObjectDumper.Write(q)
}


Hence The LinQ “ SKIP” operator lets you skip the results you want, and “Take” Operator enables you yo select the rest of result . So By Using Skip and Take Operator, You can create paging of Specific sequence.

10. What is Linq to SQL Deferred Loading?

(C#) - Deferred Loading is a property of Linq to sql, by default it is set true,
Example - Let's have two tables -
Blogs Table (BlogID ,Blog Name,owner) and Post table ( PostID, BlogID, Title, Body)
To find Name and No's of posts in each blog:

BlogDataContext ctx = new BlogDataContext( );
var query = from b in ctx.Blogs select b;
foreach (Blog b in query)
{
Console.WriteLine("{0} has {1} posts", b.BlogName,
b.Posts.Count);
}


Output of queries Produce Blog name with no's of post, But For each Blog Looping will be occurs (in case long list of blogs) that's reduces Overall Performance that's called the Deferred loading.

Download Interview PDF