예제 #1
0
        public static void Example2()
        {
            var dates = new DateTimeRange(SampleData.Start, SampleData.End);

            var query = from date in dates
                        join defect in SampleData.AllDefects
                        on date equals defect.Created.Date
                        into joined
                        select new { Date = date, Count = joined.Count() };

            foreach (var grouped in query)
            {
                Console.WriteLine("{0:d}: {1}", grouped.Date, grouped.Count);
            }

            /* YOu can check syntax of
             *  IEnumerable<String> a;
             *  a.GroupJoin
             *  it is exactly the same as for inner joins, except that the resultSelector parameter has to work with a sequence of right-hand elements, not just a single one.
             */

            //Translated query
            dates.GroupJoin(SampleData.AllDefects,
                            date => date,
                            defect => defect.Created.Date,
                            (date, joined) => new { Date = date, Count = joined.Count() });
        }
예제 #2
0
        public void GroupJoin()
        {
            var query = from defect in SampleData.AllDefects
                        join subscription in SampleData.AllSubscriptions
                        on defect.Project equals subscription.Project
                        into groupedSubscriptions
                        select new { Defect = defect, Subscriptions = groupedSubscriptions };

            foreach (var entry in query)
            {
                Console.WriteLine(entry.Defect.Summary);
                foreach (var subscription in entry.Subscriptions)
                {
                    Console.WriteLine(" {0}", subscription.EmailAddress);
                }
            }

            var dates = new DateTimeRange(SampleData.Start, SampleData.End);

            var query1 = from date in dates
                         join defect in SampleData.AllDefects
                         on date equals defect.Created.Date
                         into joined
                         select new { Date = date, Count = joined.Count() };

            foreach (var grouped in query1)
            {
                Console.WriteLine("{0:d}: {1}", grouped.Date, grouped.Count);
            }


            var query2 = SampleData.AllDefects.GroupJoin(
                SampleData.AllSubscriptions,
                c => c.Project,
                c => c.Project,
                (a, b) => new { Defect = a, Subscriptions = b }
                );

            foreach (var entry in query2)
            {
                Console.WriteLine(entry.Defect.Summary);
                foreach (var subscription in entry.Subscriptions)
                {
                    Console.WriteLine(" {0}", subscription.EmailAddress);
                }
            }

            var query3 = dates.GroupJoin(SampleData.AllDefects, c => c, c => c.Created.Date,
                                         (a, b) => new { Date = a, Count = b.Count() });

            foreach (var q in query3)
            {
                Console.WriteLine("{0:d}: {1}", q.Date, q.Count);
            }
        }