Developing Microsoft Azure and Web Services — Question 101
You are developing an ASP.NET MVC application. The application has a page that updates an image stored in a database. Members of the EntityClient namespace are used to access an Entity Framework data model. Images and associated metadata are stored in a single database table.
You need to run a single query that updates an image and associated metadata in the database while returning only the number of affected rows.
Which method of the EntityCommand type should you use?
Answer options
- A. ExecuteScalar()
- B. ExecuteDbDataReader()
- C. ExecuteReader()
- D. ExecuteNonQuery()
Correct answer: D
Explanation
The correct method is ExecuteNonQuery() because it is designed to execute commands that do not return rows, such as updates, and it provides the number of rows affected. ExecuteScalar() returns a single value, which is not suitable for this scenario, while ExecuteDbDataReader() and ExecuteReader() are used for retrieving data rather than executing updates.