Beispiel #1
0
        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}");
                }
            }
        }
Beispiel #2
0
        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}");
                }
            }
        }
Beispiel #3
0
        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);
                }
            }
        }