LINQ02-Notes
LINQ02-Notes
• Extension Method: For all collections that implement the interface "IEnumerable"
• Usage: You can use "LINQ Operators" against the data [stored in sequence] regardless of the
data store [SQL Server, MySQL, Oracle].
Sequence
2. Remote: L2EF
LINQ Syntax
1. Fluent Syntax
2. Query Syntax
• Deferred Execution
• Immediate Execution
LINQ Categories
o Get products ordered by price ascending and the number of items in stock
o ToList: Takes the elements from the given source and returns a new List.
o OfType(): Returns the elements of a specific type, ignoring other elements from the
list/collection.
o The only way to call them is as static methods from the Enumerable class.
8. Set Operators [Union Family] - Deferred Execution
o Intersect: Returns elements in the 1st sequence that exist in the 2nd sequence.
o Except: Returns elements in the 1st sequence that do not exist in the 2nd sequence.
o All: If all elements in the sequence match the condition, it returns True.
o ZIP: Produces a sequence with elements from two or three specific sequences.
o Get products in stock grouped by category that contains more than 10 products.
o Get category name of products in stock that contain more than 10 products and the
number of products in each category.
o Skip: Skips a number of elements from the first and gets the rest of the elements.
o SkipLast: Skips a number of elements from the last and gets the rest of the elements.
o TakeWhile: Takes elements until an element that does not match the condition is found.
o SkipWhile: Skips elements until an element that does not match the condition is found.