LINQ expression
The Linq important part of Linq is about
getting sequences from data sources. By default, the data sources that can be
requested by Linq are:
Object (Linq to Objetcs)
XML fragments or docs (Linq to XML)
ADO.Net
DataSet (Linq to DataSet)
SQL Server (Linq to SQL)
Entity
Framework (Linq to Entities
LINQ is a unified programming model for any kind of data.
var result = from s in stringList
where s.Contains("Tutorials")
select s;
result = result variable
s = Now property of
stringList transfer in s (range variable)
strList = Sequence
| Queryable collection
Contains = Conditional Expression
Where
and Select = Standard Query
Operators
- From s in student select s.studentid, s.studentname;
- From s in student select s.studentid == 10;
Q) Display all the students whose roll no is 15
In SQL - Select * From Where
In LINQ - From s in
student select Rollno = 15;
Simple Where clause
var query_where1 = from a in AccountSet
where a.Name.Contains("Atul")
select a;
Multiple Select and where operator
Example: Multiple Select and where Operator
var
studentNames = studentList.Where(s => s.Age > 18)
.Select(s => s)
.Where(st => st.StandardID > 0)
.Select(s => s.StudentName);
Example: LINQ Query returns Collection of Anonymous Objects
var
teenStudentsName = from s in studentList
where s.age > 12 && s.age < 20
select new { StudentName = s.StudentName };
Q) 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
Q) What are the types of LINQ?
LINQ to Objects
LINQ
to XML
LINQ to Dataset
LINQ to
SQL
LINQ to Entities
Q) What are Anonymous Types?
Anonymous types are types that are generated by compiler at
run time. When we create a anonymous type we do not specify a name. We just
write properties names and their values. Compiler at runtime create these
properties and assign values to them.
var k = new {
FirstProperty = "value1", SecondProperty = "value2" };
Console.WriteLine(k.FirstProperty);
Q) What is Anonymous function?
An Anonymous function is a special function which does not have
any name. We just define their parameters and define the code into the curly
braces.
Q) Define what is let clause?
In a query
expression, it is sometimes useful to store the result of a sub-expression in
order to use it in subsequent clauses. You can do this with the let keyword,
which creates a new range variable and initializes it with the result of the
expression you supply.
LinQ Operators
Filtering Operators - Where
- OfType
Filtering is an operation to restrict the result set
such that it has only selected elements satisfying a particular condition.
Disclaimer
All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.