Developing Microsoft Azure and Web Services — Question 11
You are developing an ASP.NET MVC application. The application has a page that searches for and displays an image stored in a database. Members of the
EntityClient namespace are used to access an ADO.NET Entity Framework data model Images and associated metadata are stored in a database table.
You need to run a query that returns only the image while minimizing the amount of data that is transmitted.
Which method of the EntityCommand type should you use?
Answer options
- A. ExecuteScalar
- B. ExecuteDbDataReader
- C. ExecuteReader
- D. ExecuteNonQuery A
Correct answer:
Explanation
The correct method is ExecuteScalar, as it is designed to return a single value, which is ideal for retrieving just the image without additional data. The other options, such as ExecuteDbDataReader and ExecuteReader, are used for retrieving multiple rows or columns, which would increase the amount of data transmitted. ExecuteNonQuery is meant for executing commands that do not return data, making it unsuitable for this scenario.