Пример #1
0
        /// <summary>
        /// レコード更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            LogClear();
            try
            {
                // Dapper+FastCrud
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    foreach (var emp in conn.Find<Entity.Models.Employee>(whereClause: $"department_id<110"))
                    {
                        emp.Name = $"{emp.Name}_{emp.Id}";
                        conn.Update(emp);
                    }
                    var finish = DateTime.Now;
                    Log("FC# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                // Microsoft EntityFramework
                using (var db = new Entity.EFModels.Model1())
                {
                    var start = DateTime.Now;
                    foreach (var emp in from t1 in db.Employees where t1.department_id < 310 select t1)
                    {
                        emp.name = $"{emp.name}_{emp.id}";
                    }
                    db.SaveChanges();
                    var finish = DateTime.Now;
                    Log("EF6# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// 日本語での検索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch2_Click(object sender, RoutedEventArgs e)
        {
            LogClear();
            try
            {
                int i = 0;
                // Dapper
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    foreach (var emp in conn.Query<Entity.Models.Employee>("select * from employees where name=@Name", new { Name = "山田太郎" }))
                    {
                        if (i++ % 100 == 0) Log("{0}", emp.ToString());
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("Dapper# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                i = 0;
                // Dapper+FastCrud(プレースホルダマッピングを使用)
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    foreach (var emp in conn.Find<Entity.Models.Employee>(whereClause: $"name=@Name", queryParameters: new { Name = "山田太郎" }))
                    {
                        if (i++ % 100 == 0) Log("{0}", emp.ToString());
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("FC1# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                i = 0;
                // Dapper+FastCrud(SQL文字列だけで検索)
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    foreach (var emp in conn.Find<Entity.Models.Employee>(whereClause:$"name=N'山田太郎'")) // SQL Serverでは文字列リテラルの前にNが必要
                    {
                        if (i++ % 100 == 0) Log("{0}", emp.ToString());
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("FC2# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                i = 0;
                // Microsoft EntityFramework
                using (var db = new Entity.EFModels.Model1())
                {
                    var start = DateTime.Now;
                    foreach (var emp in from t1 in db.Employees where t1.name == "山田太郎" select t1)
                    {
                        if (i++ % 100 == 0) Log($"id={emp.id}, name={emp.name}, department_id={emp.department_id}");
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("EF6# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// レコード検索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            LogClear();
            try
            {
                int i = 0;
                // Dapper+FastCrud
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    foreach (var emp in conn.Find<Entity.Models.Employee>(whereClause: $"department_id<120"))
                    {
                        if (i++ % 100 == 0) Log("{0}", emp.ToString());
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("FC# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                i = 0;
                // Microsoft EntityFramework
                using (var db = new Entity.EFModels.Model1())
                {
                    var start = DateTime.Now;
                    foreach (var emp in from t1 in db.Employees where t1.department_id < 310 select t1)
                    {
                        if (i++ % 100 == 0) Log($"id={emp.id}, name={emp.name}, department_id={emp.department_id}");
                    }
                    var finish = DateTime.Now;
                    Log($"count = {i}");
                    Log("EF6# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// データ投入ボタン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInsert_Click(object sender, RoutedEventArgs e)
        {
            LogClear();
            var N = 2000;
            try
            {
                using (var conn = ConnectionManager.GetConnection())
                {
                    Log($"Insert records... (N={N})");
                    var dep1 = new Entity.Models.Department() { ID = 5000, NAME = "営業部" };
                    conn.Insert(dep1);
                    var dep2 = new Entity.Models.Department() { ID = 5001, NAME = "開発部" };
                    conn.Insert(dep2);
                    var dep3 = new Entity.Models.Department() { ID = 6000, NAME = "経理部" };
                    conn.Insert(dep3);

                    var emp1 = new Entity.Models.Employee() { Id = 10, Name = "山田太郎", DepartmentId = 5000 };
                    conn.Insert(emp1);
                    var emp2 = new Entity.Models.Employee() { Id = 11, Name = "山田花子", DepartmentId = 5002 };
                    conn.Insert(emp2);
                    var emp3 = new Entity.Models.Employee() { Id = 12, Name = "田中一郎", DepartmentId = 5000 };
                    conn.Insert(emp3);
                    Log("Success!");
                }

                // Microsoft EntityFramework
                using (var db = new Entity.EFModels.Model1())
                {
                    var start = DateTime.Now;
                    for (var i = 10000; i < 10000+N; i++)
                    {
                        db.Employees.Add(new Entity.EFModels.Employee() { id = i, name = "森山太郎", department_id = i/100 });
                        db.SaveChanges();
                    }
                    var finish = DateTime.Now;
                    Log("EF6# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

                // Dapper+FastCrud
                using (var conn = ConnectionManager.GetConnection())
                {
                    var start = DateTime.Now;
                    for (var i = 30000; i < 30000+N; i++)
                    {
                        var emp1 = new Entity.Models.Employee() { Id = i, Name = "広末直美", DepartmentId = i/100 };
                        conn.Insert(emp1);
                    }
                    var finish = DateTime.Now;
                    Log("FC# start:{0} finish:{1} ({2})", start, finish, finish - start);
                }

            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }