February 2010
Intermediate to advanced
1043 pages
28h 24m
English
This chapter describes each of the LINQ query operators. As well as serving as a reference, two of the sections, Projecting and Joining, cover a number of conceptual areas:
Projecting object hierarchies
Joining with Select, SelectMany, Join, and GroupJoin
Outer range variables in query expressions
All of the examples in this chapter assume that a names array is defined as follows:
string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };Examples that query a database assume that a typed DataContext variable called dataContext is instantiated as follows:
var dataContext = new NutshellContext ("connection string..."); ... public class NutshellContext : DataContext { public NutshellContext (string cxString) : base (cxString) {} public Table<Customer> Customers { get { return GetTable<Customer>(); } } public Table<Purchase> Purchases { get { return GetTable<Purchase>(); } } } [Table] public class Customer { [Column(IsPrimaryKey=true)] public int ID; [Column] public string Name; [Association (OtherKey="CustomerID")] public EntitySet<Purchase> Purchases = new EntitySet<Purchase>(); } [Table] public class Purchase { [Column(IsPrimaryKey=true)] public int ID; [Column] public int? CustomerID; [Column] public string Description; [Column] public decimal Price; [Column] public DateTime Date; EntityRef<Customer> custRef; [Association (Storage="custRef",ThisKey="CustomerID",IsForeignKey=true)] public Customer Customer { get { return custRef.Entity; } set { custRef.Entity ...Read now
Unlock full access