コード例 #1
0
        public void GroupJoin()
        {
            var employees  = Employee.GetEmployeesArrayList();
            var empOptions = EmployeeOptionEntry.GetEmployeeOptionEntries();

            var linq = employees
                       .GroupJoin(
                empOptions,
                e => e.id,
                o => o.id,
                (e, os) => new
            {
                id      = e.id,
                name    = $"{e.firstName} {e.lastName}",
                options = os.Sum(o => o.optionsCount)
            }).ToArray();

            var meta = employees.MetaOperators()
                       .GroupJoinBox(
                empOptions.MetaWrapper(),
                e => e.id,
                o => o.id,
                pair => new
            {
                id      = pair.First.id,
                name    = $"{pair.First.firstName} {pair.First.lastName}",
                options = pair.Second.MetaOperators().Select(o => o.optionsCount).Sum()
            }).ToArray();

            Assert.Equal(linq, meta);
        }
コード例 #2
0
        public void GroupJoinSecondHasOverhead()
        {
            var employees  = Employee.GetEmployeesArrayList();
            var empOptions = EmployeeOptionEntry.GetEmployeeOptionEntries();


            var linq = employees
                       .GroupJoin(
                empOptions.Where((entry, i) => i % 2 == 0),
                e => e.id,
                o => o.id,
                (e, os) => new
            {
                id      = e.id,
                name    = $"{e.firstName} {e.lastName}",
                options = os.Sum(o => o.optionsCount)
            }).ToArray();

            var meta = employees.MetaOperators()
                       .GroupJoinBox(
                empOptions.MetaOperators().WhereIndex(pair => pair.Index % 2 == 0).Collect,
                e => e.id,
                o => o.id,
                pair => new
            {
                id      = pair.First.id,
                name    = $"{pair.First.firstName} {pair.First.lastName}",
                options = pair.Second.MetaOperators().Select(o => o.optionsCount).Sum()
            }).ToArray();

            Assert.Equal(linq, meta);
        }
コード例 #3
0
ファイル: GrupByTest.cs プロジェクト: blowin/LinqMeta
        public void GroupBy()
        {
            var linq = EmployeeOptionEntry
                       .GetEmployeeOptionEntries()
                       .GroupBy(entry => entry.id)
                       .Select(entries => entries.ToList())
                       .ToList();

            var meta = EmployeeOptionEntry
                       .GetEmployeeOptionEntries().MetaOperators()
                       .GroupBy(entry => entry.id)
                       .Select(pair => pair.Second.MetaOperators().ToList())
                       .ToList();

            Assert.True(EmployeeOptionEntry.Compare(linq, meta));
        }