Chapter 21: LINQ
Quiz Solutions
Solution to Question 21-1. LINQ allows you to query several different types of data sources, including SQL Server databases, XML files, and in-memory collections.
Solution to Question 21-2. A LINQ query returns a collection that implements IEnumerable
. The type of the objects in the collection is irrelevant.
Solution to Question 21-3. The select
keyword returns the result of a LINQ query.
Solution to Question 21-4. You don’t need to use any special syntax to return a complex type from a LINQ query. The compiler can infer the type, even if it’s unnamed.
Solution to Question 21-5. The range variable in a LINQ query doesn’t have to be any type; it just has to be a valid C# name. The compiler will infer its type.
Solution to Question 21-6. The lambda expression in a LINQ query returns a method used to evaluate the data set. That data is projected onto the range variable.
Solution to Question 21-7. When you use LINQ to SQL, you need to add a reference to the System.Data.Linq
namespace, not the System.Linq
namespace that’s added by default and supports all the basic LINQ functions.
Solution to Question 21-8. Use the [Table]
attribute, with the Name
of the table to define a class as representing a SQL table.
Solution to Question 21-9. To add table classes in the Object Relational Designer, you must establish a connection to the database, and then simply drag the tables onto the design surface. The classes will be generated for you automatically.
Solution to Question ...
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.