LINQ Flashcards
What is a LINQ query?
LIQN allows you to query data from different types of data using a single syntax.
What are the interface types that LINQ can query?
Link can query any IEnumerable
What is the basic structure of a LINQ query?
var myQuery = from user in users where user.contains(“m”) ordery by user.Length ascending select user;
When will the LINQ query be executed?
When any operation that demands the fetch be executed (count, toList() and etc).
How to group results using LINQ?
var userQuery = from user in users group user by user.length into userGroup select userGroup. Then it is necessary to loop in the user group and use userGroup.Key in order to get the value of the group aggregator.
What does LINQ stand for?
Stands for Language Integrated Query.
How interpolate strings in C#?
By using var myString = $”The count of users is: {users.Count}”
What was the need behind LINQ before it was invented?
Each type of collection needed its own query mechanism, then LINQ purpose is to integrate them all into a single mechanism. types of common collections: object data, relational data and xml data.
How the sort was implemented before LINQ?
By implementing your own class that implements IComparer.
how to get just the fist five items of a list?
By using the .Take(5) method.
Is there one way to invoke a LINK query?
No… you can also call simplified methods. such as: myList.OrderByDescending(l => l.myValue).Take(5)
What is the LINQ query syntax?
Is the syntax that looks very similar to a regular SQL query. Always starts with the from keyword. Similar to for in syntax. Always end with the select keyword.
Why does the query syntax starts with from and ends with select?
The language designers made this decision to increase the support of Intelisense once it is upfront known what the type the query is.
What is the extension method syntax?
Is when you filter, order and do other operations using methods only. list.orderby…
Are all extension methods available for LINQ syntaxes (query and method)?
No. method syntax has a few more methods. Usually when you want to use, count, take and skip you’ll go for the method syntax.