コード例 #1
0
ファイル: SelectManyTests.cs プロジェクト: gabla5/SO-Answers
        public void testing_select_many_with_linq_to_sql_objects()
        {
            var ctx = new PubsDataContext();

            var q = from e in ctx.employee
                    from j in ctx.jobs
                    orderby e.fname, e.lname, j.job_desc
                    select new
                    {
                        Employee = e,
                        Job = j
                    };

            Console.WriteLine(q);
            q.Should().NotBeNull().And.NotBeEmpty();
            foreach (var item in q)
            {
                Console.WriteLine(
                    string.Format(
                    "Employee: {0} - Job: {1}",
                    item.Employee.fname + " " + item.Employee.lname,
                    item.Job.job_desc
                    ));
            }

            var r = ctx.employee.OrderBy(x => x.fname).ThenBy(x => x.lname).SelectMany(
                x => ctx.jobs.OrderBy(c => c.job_desc),
                (x, y) => new
                {
                    Employee = x,
                    Job = y
                });

            Console.WriteLine(r);
            r.Should().NotBeNull().And.NotBeEmpty();
            foreach (var item in r)
            {
                Console.WriteLine(
                    string.Format(
                    "Employee: {0} - Job: {1}",
                    item.Employee.fname + " " + item.Employee.lname,
                    item.Job.job_desc
                    ));
            }
        }
コード例 #2
0
ファイル: InnerJoinsTests.cs プロジェクト: jupaol/SO-Answers
        public void testing_simple_inner_join_sentences()
        {
            var ctx = new PubsDataContext();

            var q = from e in ctx.employee
                    join j in ctx.jobs
                    on e.job_id equals j.job_id
                    orderby e.fname, e.lname, j.job_desc
                    select new
                    {
                        Employee = e,
                        Job = j
                    };

            q.Should().NotBeNull().And.NotBeEmpty();
            foreach (var item in q)
            {
                Console.WriteLine(item.Employee.fname + " " + item.Employee.lname + " With job: " + item.Job.job_desc);
            }

            var w = ctx.employee.Join(
                ctx.jobs,
                x => x.job_id,
                x => x.job_id,
                (x, y) => new
                {
                    Employee = x,
                    Job = y
                }).OrderBy(x => x.Employee.fname).ThenBy(x => x.Employee.lname).ThenBy(x => x.Job.job_desc);

            w.Should().NotBeNull().And.NotBeEmpty();
            foreach (var item in w)
            {
                Console.WriteLine(item.Employee.fname + " " + item.Employee.lname + " With job: " + item.Job.job_desc);
            }
        }