コード例 #1
0
ファイル: Program.cs プロジェクト: riezebosch/adonetb
        static void Main(string[] args)
        {
            using (var context = new SchoolEntities())
            {

                var query = from p in context.People.ToList()
                            where IsValid(p.FirstName)
                            select p.FirstName + " " + p.LastName;

                //Console.WriteLine(query);

                //foreach (var p in query)
                //{
                //    Console.WriteLine(p);
                //}

                foreach (var person in context
                    .People
                    .OfType<Student>()
                    .Include(p =>
                        p.Grades.Select(g => g.Course)))
                {
                    Console.WriteLine(person.FirstName);

                    foreach (var grade in person.Grades)
                    {
                        Console.WriteLine("  {1}: {0}", grade.Grade, grade.Course.Name);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: riezebosch/adonetb1
        static void Main(string[] args)
        {
            var sw = Stopwatch.StartNew();

            using (var conn = new SqlConnection("Data Source=.;Initial Catalog=School;Integrated Security=SSPI"))
            using (var comm = new SqlCommand("SELECT FirstName, LastName FROM Person WHERE FirstName = 'Peggy'", conn))
            {
                conn.Open();

                sw.Restart();

                var reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine(reader[0] + " " + reader[1]);
                }

                Console.WriteLine(sw.Elapsed);
            }

            using (var entities = new SchoolEntities())
            {
                sw.Restart();
                var query = from p in entities.People
                            where p.FirstName == "Peggy"
                            select p.FirstName + " " + p.LastNogWatName;

                foreach (var name in query)
                {
                    Console.WriteLine(name);
                }

                Console.WriteLine(sw.Elapsed);

                sw.Restart();
                var query2 = from p in entities.People
                            where p.FirstName == "Peggy"
                            select p.FirstName + " " + p.LastNogWatName;

                foreach (var name in query2)
                {
                    Console.WriteLine(name);
                }

                Console.WriteLine(sw.Elapsed);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: riezebosch/adonetb
        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            
            using (new TransactionScope())
            using (var context = new SchoolEntities())
            {
                await Task.Run(() => context.People.AddRange(Enumerable.Range(0, 10000).Select(i => new Student { FirstName = "Student" + i, EnrollmentDate = DateTime.Today })));
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            button1.Enabled = true;
        }