Esempio n. 1
0
        ///-----------------------------------------------------------------------------------------
        /// <summary>
        /// Run #1 : took 3,376 ms to insert 500,000
        /// </summary>
        /// <returns></returns>
        public int InsertUsers(int newUserCount)
        {
            Stopwatch    sw     = new Stopwatch();
            const string sqlCmd = "Insert DbDemo.Dbo.Ssn ( SsnId, Ssn1, Ssn2, Ssn3 ) " +
                                  "values( @ssnId, @ssn1, @ssn2, @ssn3 ) " +

                                  "Insert DbDemo.Dbo.Users ( FirstName, LastName, SsnId ) " +
                                  "values (@firstName, @lastName, @ssnId )";

            var userList = CreateUserList(newUserCount, 1, 1, 1);

            int count = 0;

            sw.Restart();
            foreach (var user in userList)
            {
                var parms = new Dahl.Data.SqlServer.CommandParameter
                {
                    CreateParameter("@firstName", $"First{user.fk_Ssn.Ssn1:D3}-{user.fk_Ssn.Ssn2:d2}-{user.fk_Ssn.Ssn3:D4}"),
                    CreateParameter("@lastName", $"Last{user.fk_Ssn.Ssn1:D3}-{user.fk_Ssn.Ssn2:d2}-{user.fk_Ssn.Ssn3:D4}"),
                    CreateParameter("@ssnId", user.fk_Ssn.SsnId),
                    CreateParameter("@ssn1", user.fk_Ssn.Ssn1),
                    CreateParameter("@ssn2", user.fk_Ssn.Ssn2),
                    CreateParameter("@ssn3", user.fk_Ssn.Ssn3)
                };
                count += Database.ExecuteCommand(sqlCmd, parms);
                if (Database.LastError.Code != 0)
                {
                    break;
                }
            }
            sw.Stop();
            Trace.WriteLine($"InsertUsers -- Records Inserted: {count} --- Time to insert: {sw.ElapsedMilliseconds} ms");
            return(count);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Course GetCourse(string name)
        {
            const string sqlCmd = "select * from Courses where [Name] like @name";
            var          parms  = new Dahl.Data.SqlServer.CommandParameter
            {
                CreateParameter("@name", name)
            };

            var result = Database.ExecuteQuery <Course>(sqlCmd, parms)?.ToList();

            if (result != null && !result.Any())
            {
                return(null);
            }

            return(result?.ToList()[0]);
        }
Esempio n. 3
0
        public List <Models.Users> LoadOneUser()
        {
            const string sqlCmd = "select * from Users where LastName like @lastName ";
            var          parms  = new Dahl.Data.SqlServer.CommandParameter
            {
                CreateParameter("@lastName", "Last001-01-0002")
            };

            Stopwatch sw = new Stopwatch();

            sw.Restart();
            var users = Database.ExecuteQuery(sqlCmd, parms, new Models.UsersMap()).ToList();

            sw.Stop();
            Trace.WriteLine($"LoadUsers(IDatabase database) ExecuteQuery returned {users.Count} user taking {sw.ElapsedMilliseconds:N0} ms.");

            Assert.IsNotNull(users);
            return(users);
        }