LINQ To Object
LINQ To Object
LINQ to Object
Why a businessman needs
software?
To automate his business (data)
Where does the data stored?
• SqlConnection
• Query
• Execution procedure etc
Working with ADO.NET
• DataTable
• DataSet
• SqlDataAdapter etc
Working with RAM data
In simplified english:
from variable in source
In syntax:
from customerObject in Customers
How it works?
In simplified english:
from variable in source
where the condition is true
In syntax:
from customerObject in Customers
where customerObject.Name == "Foysal"
How it works?
In simplified english:
from variable in source
where the condition is true
select data
In syntax:
from customerObject in Customers
where customerObject.Name == "Foysal"
select customerObject;
Types of LINQ
• LINQ to Object
• LINQ to SQL
• LINQ to XML
Types of LINQ
Initialization Expression:
Example:
new {studentObject.Name,studentObject.Address};
Example:
or
Practice:
1. Get the student list who live in Shamoli.
2. Get the names which has the length of more than 6
How to work well in .NET
To work better with a tool, you must know what can you
do with that tool. Remember, Language (C# for
example) is just a tool for your coding. So, you have to
know what can you do with this tool.
Example:
var selectedNames = from name in names
where name.EndsWith("l")
select name;
or
Practice:
1. Find the names which contains the string sequence
of "on"
2. Find the student list who has address containing the
string sequence of "li"
Projection Operator: Select
By this operator, we select our data in different ways.
Example:
var selectedNames = from name in names
where name.Contains("Foysal")
select name;
Or,
Practice:
1. Find the courses which are taken by the students who lives
in Shamoli.
2. Find the course Credit of the courses which are taken by the
students whose name are 6 character long.
What else we can do with it?
There are several more operator in LINQ. Such as:
• Partitioning Operators
• Ordering Operators
• Grouping Operators
• Set Operators
• Conversion Operators
• Element Operators
• Generation Operators
• Quantifiers
• Aggregate Operators
• Miscellaneous Operators
• Custom Sequence Operators
• Query Execution
• Join Operators
• Utility Routines
Next Day: “LINQ to SQL”