コード例 #1
0
ファイル: Program.cs プロジェクト: idofl/Demos.NDC2016.EFCore
        private static void EagerLoad()
        {
            using (var context = new EFCore.StarWarsContext(_optionsBuilder.Options))
            {
                var query = from p in context.People.Include(person => person.Starships)
                            where p.Name.StartsWith("Luke")
                            select p;

                Console.WriteLine("With EF Core:");
                query.ToList().ForEach(p =>
                {
                    Console.WriteLine(p.Name);
                    p.Starships.ForEach(s =>
                    {
                        Console.WriteLine($"   {s.Name}");
                    });
                });
            }
            Console.WriteLine();
            using (var context = new EF6.StarWarsContext())
            {
                var query = from p in System.Data.Entity.QueryableExtensions.Include(
                    context.People, person => person.Starships)
                            where p.Name.StartsWith("Luke")
                            select p;

                Console.WriteLine("With EF 6:");
                query.ToList().ForEach(p =>
                {
                    Console.WriteLine(p.Name);
                    p.Starships.ForEach(s =>
                    {
                        Console.WriteLine($"   {s.Name}");
                    });
                });
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: idofl/Demos.NDC2016.EFCore
        private static void MixClientAndSql()
        {
            using (var context = new EFCore.StarWarsContext(_optionsBuilder.Options))
            {
                var query = context.People
                            .FromSql($"Select * from people where {nameof(EFCore.Person.Height)} > {{0}}", 1.5)
                            .OrderByDescending(p => p.Height);

                Console.WriteLine("With EF Core:");
                query.ToList().ForEach(
                    p => Console.WriteLine($"{p.Name}-{p.Height}"));
            }
            Console.WriteLine();
            using (var context = new EF6.StarWarsContext())
            {
                var query = context.People
                            .SqlQuery($"Select * from people where {nameof(EFCore.Person.Height)} > {{0}}", 1.5)
                            .OrderByDescending(p => p.Height);

                Console.WriteLine("With EF 6:");
                query.ToList().ForEach(
                    p => Console.WriteLine($"{p.Name}-{p.Height}"));
            }
        }