Flylib.com
List of Listings
Previous page
Table of content
Next page
Chapter 1: LINQ Introduction
Listing 1-1: Type declarations with simple relationships
Listing 1-2: Type declarations with two-way relationships
Listing 1-3: Class declaration mapped on a database table
Listing 1-4: Database update calling the SubmitChanges method
Listing 1-5: A fragment of an XML file of orders
Listing 1-6: Reading the XML file of orders using an XmlReader
Listing 1-7: Reading the XML file using LINQ to XML
Listing 1-8: Reading the XML file using LINQ to XML and Visual Basic 9.0 syntax
Listing 1-9: Creating the XML of orders using Visual Basic 9.0 XML literals
Listing 1-10: C# code equivalent to a LINQ query over Reflection
Listing 1-11: LINQ query that gets temporary files greater than 10,000 bytes, ordered by size
Chapter 2: C# Language Features
Listing 2-1: Delegate declaration
Listing 2-2: Delegate instantiation (C# 1.x)
Listing 2-3: Delegate instantiation (C# 2.0)
Listing 2-4: Common use for a delegate
Listing 2-5: Using an anonymous method
Listing 2-6: Parameters for an anonymous method
Listing 2-7: IEnumerator and IEnumerable declarations
Listing 2-8: Enumerable class
Listing 2-9: Sample enumeration code
Listing 2-10: Enumeration using a foreach statement
Listing 2-11: Enumeration using a yield statement
Listing 2-12: Multiple yield statements
Listing 2-13: Enumeration using yield (typed)
Listing 2-14: Explicitly typed parameter list
Listing 2-15: Implicitly typed parameter list
Listing 2-16: Expression body
Listing 2-17: Lambda expression examples
Listing 2-18: Lambda expression as a predicate
Listing 2-19: Use of an expression tree
Listing 2-20: Extension methods declaration
Listing 2-21: Extension methods for native value types
Listing 2-22: Extension methods call order
Listing 2-23: Extension methods overload
Listing 2-24: Instance method over extension methods
Listing 2-25: Extension methods resolution
Listing 2-26: Lambda expression as predicate
Listing 2-27: Standard syntax for object initialization
Listing 2-28: Object initializer
Listing 2-29: Explicit constructor call in object initializer
Listing 2-30: Nested object initializers
Listing 2-31: Initializers for owned objects
Listing 2-32: Collection initializers
Listing 2-33: Anonymous types definition
Listing 2-34: Implicitly typed arrays
Chapter 3: Visual Basic 9.0 Language Features
Listing 3-1: Nullable type declarations
Listing 3-2: Nullable type conversions
Listing 3-3: Local type inference
Listing 3-4: Changed behavior from Visual Basic 8.0 to Visual Basic 9.0
Listing 3-5: Standard method declaration and use
Listing 3-6: Extension method declaration
Listing 3-7: Extension method use
Listing 3-8: Sample class for object initializers
Listing 3-9: Initialization using With statement
Listing 3-10: Object initializer syntax
Listing 3-11: Object initializer syntax on multiple lines
Listing 3-12: Object initializer syntax and local type inference
Listing 3-13: Object initializers using expressions
Listing 3-14: Nested object initializers
Listing 3-15: Anonymous type definition
Listing 3-16: Array of anonymous types
Listing 3-17: Simple LINQ query
Listing 3-18: Order By in C# 3.0
Listing 3-19: Order By in Visual Basic 9.0
Listing 3-20: Lambda expressions in Visual Basic 9.0
Listing 3-21: Use of lambda expressions in query expressions
Listing 3-22: Closures with query expressions
Listing 3-23: XML literal used as a constant
Listing 3-24: Invalid XML literals
Listing 3-25: XML literal in a dynamic expression
Listing 3-26: Dynamic XML tags in an XML literal
Listing 3-27: Dynamic XML tags in explicit method calls
Listing 3-28: Closing tag for dynamic XML tags
Listing 3-29: Nested list of XML literals
Listing 3-30: Query embedded into an XML literal
Listing 3-31: Child axis
Listing 3-32: Attribute axis
Listing 3-33: Descendants axis
Listing 3-34: Relaxed delegates
Listing 3-35: Relaxed delegates with signature inference
Chapter 4: LINQ Syntax Fundamentals
Listing 4-1: A simple LINQ query
Listing 4-2: The first LINQ query translated into basic elements
Listing 4-3: A query with a restriction
Listing 4-4: A query with a restriction and an index-based filter
Listing 4-5: A query with a paging restriction
Listing 4-6: The list of orders made by Italian customers
Listing 4-7: The flattened list of orders made by Italian customers
Listing 4-8: The flattened list of orders made by Italian customers, written with a query expression
Listing 4-9: The list of Quantity and IdProduct of orders made by Italian customers
Listing 4-10: The list of Quantity and IdProduct of orders made by Italian customers, written with a query expression
Listing 4-11: A query expression with a descending orderby clause
Listing 4-12: A query expression with orderby and thenby
Listing 4-13: A custom comparer used with an OrderBy operator
Listing 4-14: The Reverse operator applied
Listing 4-15: The Reverse operator applied to a query expression with orderby and thenby
Listing 4-16: The GroupBy operator used to group customers by Country
Listing 4-17: A query expression with a group by syntax
Listing 4-18: The GroupBy operator used to group customer names by Country
Listing 4-19: The Join operator used to map orders with products
Listing 4-20: The Join operator query expression syntax
Listing 4-21: The GroupJoin operator used to map products with orders, if present
Listing 4-22: A query expression with a join into clause
Listing 4-23: The query expression of Listing 4-22 in its compact version
Listing 4-24: The Distinct operator applied to the list of products used in orders
Listing 4-25: The Distinct operator applied to a query expression
Listing 4-26: The Union operator applied to the second and third customer orders
Listing 4-27: The Intersect and Except operators applied to the second and third customer orders
Listing 4-28: Set operators applied to query expressions
Listing 4-29: The Count operator applied to customer orders
Listing 4-30: The Sum operator applied to customer orders
Listing 4-31: The Sum operator applied to customer orders, with a nested query
Listing 4-32: The Min operator applied to order quantities
Listing 4-33: The Min operator applied to wrong types (thereby throwing an ArgumentException)
Listing 4-34: The Max operator applied to custom types, with a value selector
Listing 4-35: Both Average operator signatures applied to product prices
Listing 4-36: Customers and their average order amounts
Listing 4-37: Customers and their most expensive orders
Listing 4-38: Products and their ordered amounts
Listing 4-39: Customers and their most expensive orders paired with the month of execution
Listing 4-40: A set of years generated by the Range operator, used to filter orders
Listing 4-41: A factorial of a number using the Range operator
Listing 4-42: The Repeat operator, used to repeat the same query many times
Listing 4-43: The Empty operator used to initialize an empty set of customers
Listing 4-44: The Any operator applied to all customer orders to check orders of IdProduct == 1
Listing 4-45: The All operator applied to all customer orders to check the quantity
Listing 4-46: The Contains operator applied to the first customer’s orders
Listing 4-47: The Take operator, applied to extract the two top customers ordered by order amount
Listing 4-48: The TakeWhile operator, applied to extract the top customers that form 80 percent of all orders
Listing 4-49: The First operator, used to select the first American customer
Listing 4-50: Examples of the FirstOrDefault operator syntax
Listing 4-51: Examples of the Single operator syntax
Listing 4-52: Examples of the ElementAt and ElementAtOrDefault operator syntax
Listing 4-53: Example of the DefaultIfEmpty operator syntax, both with default(T) and a custom default value
Listing 4-54: The Concat operator, used to concatenate Italian customers with customers from the United States
Listing 4-55: Example that shows when expression trees are evaluated
Listing 4-56: A query expression over a custom list of type Customers
Listing 4-57: A query expression over a list of Customers converted with the AsEnumerable operator
Listing 4-58: A query expression over an immutable list of Customers obtained by the ToList operator
Listing 4-59: A query expression that uses ToList to copy the result of a query over products
Listing 4-60: An example of the ToDictionary operator, applied to customers
Listing 4-61: An example of the ToLookup operator, used to group orders by product
Chapter 5: LINQ to ADO.NET
Listing 5-1: Entity definition for LINQ to SQL
Listing 5-2: Simple LINQ to SQL query
Listing 5-3: Hierarchy of classes based on contacts
Listing 5-4: Queries using a hierarchy of entity classes
Listing 5-5: Object identity
Listing 5-6: Association EntityRef
Listing 5-7: Association EntitySet (visible)
Listing 5-8: Association EntitySet (hidden)
Listing 5-9: Use of DataShape and LoadWith<T>
Listing 5-10: Use of DataShape and AssociateWith<T>
Listing 5-11: Query manipulation
Listing 5-12: Stored procedure declaration
Listing 5-13: Stored procedure with multiple results
Listing 5-14: Scalar-valued user-defined function
Listing 5-15: Table-valued user-defined function
Listing 5-16: Compiled query in a local scope
Listing 5-17: Compiled query assigned to a static member
Listing 5-18: Query with Join
Listing 5-19: Query using Association
Listing 5-20: Access through Entity
Listing 5-21: Access through Entity with a single statement
Listing 5-22: Direct query
Listing 5-23: Submit changes to the database
Listing 5-24: Retry loop for a concurrency conflict
Listing 5-25: Transaction controlled by TransactionScope
Listing 5-26: Stored procedure to override an update
Listing 5-27: Loading DataSet using a DataAdapter
Listing 5-28: Querying a DataTable with LINQ
Listing 5-29: Joining two DataTable objects with LINQ
Listing 5-30: Leveraging DataSet relationships in LINQ queries
Listing 5-31: Querying a typed DataSet with LINQ
Listing 5-32: Querying an untyped DataSet with LINQ
Listing 5-33: A handmade Customer entity
Listing 5-34: An ADO.NET Entity Framework auto-generated Customer entity
Listing 5-35: A query to select all the Italian customers
Listing 5-36: A LINQ query over a sequence of Customers entities
Chapter 6: LINQ to XML
Listing 6-1: A sample of XML functional construction
Listing 6-2: A sample of Visual Basic 9.0 XML literals
Listing 6-3: A sample XElement constructed using the LINQ to XML API
Listing 6-4: Definition of an XML element using DOM
Listing 6-5: Definition of an XML element using Visual Basic 9.0 XML literals
Listing 6-6: Sample of explicit type casting using XElement content
Listing 6-7: Sample of explicit escaping of XML text
Listing 6-8: Sample usage of the AddAfterSelf method of XNode
Listing 6-9: A LINQ to XML sentence merged with LINQ queries
Listing 6-10: A LINQ to XML sentence merged with LINQ queries, using Visual Basic 9.0 XML literals
Listing 6-11: XML namespace handling using classic DOM syntax
Listing 6-12: LINQ to XML namespace declaration
Listing 6-13: Visual Basic 9.0 XML literals used to declare XML content with a default XML namespace
Listing 6-14: Multiple XML namespaces within a single XElement declaration
Listing 6-15: LINQ to XML declaration of an XML namespace with a custom prefix
Listing 6-16: Visual Basic 9.0 XML literals used to declare an XML namespace with a custom prefix
Listing 6-17: Visual Basic 9.0 XML literals and global XML namespaces
Listing 6-18: C# 3.0 syntax used to define a default namespace and a custom prefix for one
Listing 6-19: Annotations applied to an XElement instance
Listing 6-20: Example of tag replacement using the XElement ReplaceWith method
Listing 6-21: Example of attribute and child element management using XElement methods
Listing 6-22: A sample LINQ to XML query based on the Element extension method
Listing 6-23: Another sample LINQ to XML query based on the Elements extension method
Listing 6-24: Source XML with a list of customers
Listing 6-25: Destination XML with a list of customers transformed
Listing 6-26: XSLT to transform XML from Listing 6-24 to Listing 6-25
Listing 6-27: A functional construction used to transform XML from Listing 6-24 to Listing 6-25
Listing 6-28: A Visual Basic 9.0 XML literal used to transform XML from Listing 6-24 to Listing 6-25
Listing 6-29: An XML instance to search with LINQ to XML
Listing 6-30: A LINQ to XML query to extract all city nodes from a customers list
Listing 6-31: A LINQ to XML query to extract all city nodes from a customers list after adding some customers
Listing 6-32: Using LINQ to XML and LINQ queries to query XML content
Listing 6-33: A LINQ query that merges LINQ to XML and LINQ to Objects
Listing 6-34: A LINQ query that merges LINQ to XML and LINQ to Objects, simplified by using the let clause
Listing 6-35: A LINQ query over XML, based on an XSD typed approach
Listing 6-36: An XML Schema Definition for our sample list of customers
Listing 6-37: An XML document with the schema of Listing 6-36, built using the LINQ to XML API
Listing 6-38: XML validation using the Validate extension method
Listing 6-39: XSLT transformation using XslCompiledTransform and the CreateNavigator extension method
Listing 6-40: Sample usage of the XPathEvaluate extension method
Listing 6-41: Sample LINQ query over the result of the XPathSelectElements extension method
Appendix A: ADO.NET Entity Framework
Listing A-1: A classic ADO.NET 2.0 query using a SqlDataReader
Listing A-2: A classic ADO.NET 2.0 query using DbProviderFactories
Listing A-3: A sample object-oriented definition of our conceptual entities
Listing A-4: The Customer and Order EntityType definition within Northwind.CSDL
Listing A-5: The physical data layer Customer and Order definition within Northwind.SSDL
Listing A-6: CSDL and SSDL mapping described by Northwind.MSL
Listing A-7: A sample query against a set of entities, using EntityCommand and EntityConnection
Listing A-8: An excerpt of the Customer type auto-generated from the CSDL file
Listing A-9: An excerpt of the NothwindEntities type auto-generated from the CSDL file
Listing A-10: An ADO.NET Entities query to extract all the customers
Listing A-11: An ADO.NET Entities query to extract all the typed customers
Listing A-12: An ADO.NET Entities query to extract all the customers located in Italy
Listing A-13: An ADO.NET Entities query to extract all the customers of a particular country
Listing A-14: An ADO.NET Entities query to extract all the orders of customers of a specific country
Listing A-15: An ADO.NET Entities query to extract all the customers who placed orders in the last two years
Listing A-16: A LINQ to Entities query to extract all the customers who placed orders in the last two years
Listing A-17: Entity modification and data persistence
Listing A-18: Entity status and concurrency
Listing A-19: Entity modification using TransactionScope
Previous page
Table of content
Next page
Introducing MicrosoftВ® LINQ
ISBN: 0735623910
EAN: 2147483647
Year: 2007
Pages: 78
Authors:
Paolo Pialorsi
,
Marco Russo
BUY ON AMAZON
ADO.NET 3.5 Cookbook (Cookbooks (OReilly))
Retrieving Stored Procedure Return Values Using a DataReader
Overcoming Keyword Conflicts When Using CommandBuilders
Using XPath to Query Data in a DataSet
Getting SQL Server Column Metadata Without Returning Data
Listing Tables in an Access Database
Cisco IOS in a Nutshell (In a Nutshell (OReilly))
Token Ring Interfaces
ATM
Configuring a Simple DDR Connection
Multilink PPP
Tunnels
Cisco IOS Cookbook (Cookbooks (OReilly))
Defining Per Port Privileges
Removing Private ASNs from the AS Path
Compressing Frame Relay Data with Maps
Showing HSRP State Information
Expect
Mastering Delphi 7
The Architecture of Delphi Applications
Multitier DataSnap Applications
Internet Programming: Sockets and Indy
Web Programming with IntraWeb
Using XML Technologies
An Introduction to Design Patterns in C++ with Qt 4
Optional Arguments
The Qt XML Module
Selection Statements
Simple Queries and Filters
Mp3PlayerView
Telecommunications Essentials, Second Edition: The Complete Global Source (2nd Edition)
Multimedia Networking Requirements
The Optical Core: Overlay Versus Peer-to-Peer Networking Models
Wireless Communications Regulations Issues
2G: Digital Cellular Radio
Mobile IP
flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net
Privacy policy
This website uses cookies. Click
here
to find out more.
Accept cookies