The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
QUESTION:
Given a 100 row HTML table with an id of "table1", use jQuery to make the background color of every fourth row "#eeeeee".
2) QUESTION:
Given the following C# code
a. How many times do queries execute on the database? b. On which lines will a query execute on the database? c. What is the value of temp5?
01 02 03 04 05 06 07 08 09
// there are 50 rows in states_lookup // lazy loading is enabled using (ApplicationEntities context = new ApplicationEntities()) { var temp1 = context.states_lookup; var temp2 = temp1.Take(10).Select(x => x.state_id); var temp3 = temp1.ToList(); var temp4 = temp1.Count(); var temp5 = temp4 + temp2.Count(); }
3) QUESTION:
Fix the following issues with the .NET (C# 4.0) and T-SQL (SQL Server 2008 R2) code snippet below.
Each answer MUST only change OR move ONE line of code. No exceptions. Yes, all are solvable without disobeying this rule.
Answer each question by stating what line number should be changed to what code, or what line number to move to what line number.
You can use a debugger, Google, Visual Studio, or any other programming tools.
a. The function should not be an instance method. (Answered for you as an example.)
Change line 3 to: public static int CountEmployeesByName(string[] namesToSearch) { b. The database fails to store 2 employees that have the same name. Do not sacrifice the usage of the primary key index seek for searching by name. c. The search is failing to find employees with names longer than 10 characters. d. The function should be case insensitive (finds 'Nick' when searching 'nick'). Do not sacrifice the usage of the primary key index seek for searching by name. e. The function should be accent insensitive (finds 'Niño' when searching 'Nino'). Do not sacrifice the usage of the primary key index seek for searching by name. f. The function is always failing to find any but the last name in the namesToSearch array. g. The search is somehow finding '毛泽东先生' when searching 'Наина'. h. Every matching employee record is being retrieved from the database server (very inefficient). The SQL engine should do the counting. i. The function should not be running a query for each search name. It should run exactly 1 SQL statement each time the function is called. j. One employee can be counted twice. It should return number of unique employees.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// Returns the number of unique employees that have names that match // one of the namesToSearch. public int CountEmployeesByName(string[] namesToSearch) { using (ApplicationEntities context = new ApplicationEntities()) { var queries = new List>(); string nameParam; foreach (string name in namesToSearch) { nameParam = name; //search for employees by name queries.Add(from e in context.employees where e.name == nameParam select e); } return queries .Sum(q => q.Count()); } } /*Database creation script (make corrections here too): * * CREATE TABLE dbo.employees * ( * uniqueEmployeesId int NOT NULL IDENTITY (1, 1), * name varchar(10) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL, * CONSTRAINT PK_employees PRIMARY KEY CLUSTERED ( * name * ) * ) */
//If you wish, use to verify each answer or demonstrate issue on question 3 public static void UnitTests() { //Populate with test data using (ApplicationEntities context = new ApplicationEntities()) { context.Database.ExecuteSqlCommand(@" TRUNCATE TABLE employees INSERT INTO employees (name) VALUES ('Nick'); INSERT INTO employees (name) VALUES ('Niño'); INSERT INTO employees (name) VALUES ('毛泽东先生'); SET ANSI_WARNINGS OFF; INSERT INTO employees (name) VALUES ('VeryLongName'); INSERT INTO employees (name) VALUES ('Name1'); INSERT INTO employees (name) VALUES ('Name2'); "); }
//Question 3b //The database fails to store 2 employees that have the same name. using (ApplicationEntities context = new ApplicationEntities()) { context.employees.Add(new employee() { name = "Nick" }); context.SaveChanges(); //fails with duplicate key } Debug.Assert(CountEmployeesByName(new string[] { "Nick" }) == 2); //TODO: Verify still using the primary key index seek for searching by name.
//Question 3c //The search is failing to find employees with names longer than 10 characters. Debug.Assert(CountEmployeesByName(new string[] { "VeryLongName" }) == 1); //finds 0
//Question 3d //The function should be case insensitive (finds 'Nick' when searching 'nick'). Debug.Assert(CountEmployeesByName(new string[] { "nick" }) == 1); //finds 0 //TODO: Verify still using the primary key index seek for searching by name.
//Question 3e //The function should be accent insensitive (finds 'Niño' when searching 'Nino'). Debug.Assert(CountEmployeesByName(new string[] { "Nino" }) == 1); //finds 0 //TODO: Verify still using the primary key index seek for searching by name.
//Question 3f //The function is always failing to find any but the last name in the namesToSearch array. Debug.Assert(CountEmployeesByName(new string[] { "Name1", "Name2", "NoName3" }) == 2); //finds 0
//Question 3g //The search is somehow finding '毛泽东先生' when searching 'Наина'. Debug.Assert(CountEmployeesByName(new string[] { "Наина" }) == 0); //finds 1
//Question 3h //Every matching employee record is being retrieved from the database server (very inefficient). //The SQL engine should do the counting. Debug.Assert(CountEmployeesByName(new string[] { "Nick", "Name1" }) == 3); //TODO: Verify using SQL aggregate functions using SQL Profiler
//Question 3i //The function should not be running a query for each search name. It should run exactly 1 SQL //statement each time the function is called. Debug.Assert(CountEmployeesByName(new string[] { "Nick", "Name1" }) == 3); //TODO: Verify only 1 query ran on database using SQL Profiler
//Question 3j //One employee can be counted twice. It should return number of unique employees. Debug.Assert(CountEmployeesByName(new string[] { "Name1", "name1" }) == 1); //finds 2 }
-----------