static void TryLINQtoSQL1() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var result = from user in context.Users let length = user.Name.Length orderby length select new { Name = user.Name, Length = length }; foreach (var entry in result) { Console.WriteLine($"{entry.Length}: {entry.Name}"); } } }
static void TryLINQtoSQLwithJoin() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var result = from defect in context.Defects join subscription in context.NotificationSubscriptions on defect.Project equals subscription.Project select new { defect.Summary, subscription.EmailAddress }; foreach (var entry in result) { Console.WriteLine($"{entry.Summary}: {entry.EmailAddress}"); } } }
static void TryLINQtoSQL() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var tim = context.Users .Where(user => user.Name == "Tim Trotter") .Single(); var result = from defect in context.Defects where defect.Status != Status.Closed where defect.AssignedTo == tim select defect.Summary; foreach (var summary in result) { Console.WriteLine(summary); } } }