3

I'm studying for a MS certificate. I already bumped into 3 mistakes in the test and found confirmation online.
Now I didn't really find a clear answer, so I'm posting it here.
Here's the question:

You are maintaining an existing MVC application. Users report that when querying the database for a list of products that meet specific criterion, some products do not appear in the list. The original application developer followed common MVC structure conventions. You need to locate the file that is causing the problem.
In which folder should you look for the file?

The possible answers are:

  • Controllers
  • Models
  • Views
  • Content

I would just like to know if it is I who is confused or if the question/answer itself is confusing.

6
  • Since there are already a few answers posted. Here is the answer from the practice test: ... you need to troubleshoot an application's query logic. In a standard ASP.NET application, this logic would probably be contained in the page's code-behind file. With an MVC application, most likely, that logic will be stored within the page's controller (in the Controllers folder) It seems that again the test is wrong (?) or this is just a question open for interpretation. sigh Commented Jun 27, 2011 at 12:36
  • The question is open to some interpretation! Commented Jun 27, 2011 at 12:40
  • The answer makes sense as the controller is responsible with the flow of the application data, working with data coming in, and providing data going out to relative view... but as I said it can be either way.... depends Commented Jun 27, 2011 at 12:42
  • 1
    I think you should give everybody +1 as they are all correct (i.e. the question is nebulous). ;-) Commented Jun 27, 2011 at 12:44
  • Can everyone plz give +1 to my answer... as Newton says to every action there is an equal reaction , so in return u will get +1 Commented Jun 27, 2011 at 12:46

8 Answers 8

3

Controllers is most likely the correct answer

This is a very confusing question, because its answer largely depends on your DAL strategy/library you're using. If it said you're using EF then the answer would clearly be Controllers, but if you'd be using anything more programmatic (ie repositories) then things would become more confusing.

But. When you'd be using repositories you'd probably put them in a separate project (assembly) anyway so it wouldn't be any of listed folders (if we're talking about RAW queries).

So in the case of repositories, you could still argue that data fetching/manipulation would still be done in Controllers even though it probably wouldn't be direct data querying (SQL, eSQL or LINQ) but rather calling into repositories (or even better Services that call into repositories).

What's in Models anyway?

Models usually contain classes. Either very very simple ones (as POCOs and/or DTCs) or maybe they do contain some more intelligent classes (as Entities). But in any case, you wouldn't be writing queries in classes inside Models folder but rather in Controllers that would use Models classes. Either thin or rich ones.

Sign up to request clarification or add additional context in comments.

1 Comment

The thing is the problem could either lie in the Controller asking the Model (or other repository/service) for the wrong thing, or in the Model (repository/service) erroneously interpreting the request. I think it's fair to say that it's a bit of a confusing question!
2

I would answer 'controllers' since the model (to me anyway) is dumb data the view needs in order to present itself. However, the actuall query would be implemented in a query layer.

Now there are folks that regard models as a higher concept representing business data and data access --- I just happen to not be one of them :)

3 Comments

BINGO! At least according to the practice test. Not sure if I should mark any as answer though, because obviously it's confusing / dubious.
lol --- no worries. I guess it boils down to personal preference. I have my queries in a query layer. The relevant controller uses the query layer to obtain the data and gives it to the model. The model goes to the view. In no way would I ever have a 'model' interact with a data store. But hey, that's just me :)
yes, it seems to be just you (and well, the people who wrote the practice tests) :)
1

I would say the answer is the models folder. I don't think it's confusing. The models would be where your data models would be and would most likely deal with interacting with the database. If nothing else I think the answer is obvious by process of elimination.

1 Comment

that's not what the practice test says (see my comment on my question)
1

Models - where data access services / data models are defined. As opposed to Controllers which orchestrate UI logic for Views which may, in turn, use images and styles found in Content.

3 Comments

So you would answer "Models"?
that's not what the practice test says (see my comment on my question)
Yes, and I agree that your test answer is wrong. Although potentially the controller could be passing the filter to the data access layer, and the filter could be the issue...perhaps that's what they are getting to? Here's an article by Scott Guthrie on a walkthrough intro to MVC, you can see where he puts his data access logic: weblogs.asp.net/scottgu/archive/2007/11/13/…
1

The answer would be models. This is what is/was known as your Data Access Layer. Controllers are you Business Logic that orchestrate data passing to and from DAL to presentation layer (in MVC this is Views). Views, as I just stated are presentation layer. Content usually contains images and CSS file(s).

Regards,

Huske

3 Comments

that's not what the practice test says (see my comment on my question)
Models more likely contain DTCs or richer entities or POCOs. But not direct logic. Models should contain models, not logic.
I agree with Robert here. I would usually write my data access logic in a model. The only thing that pops to my mind regards this question of yours is if for example you had a case where you use repository pattern and your interface returns an object of type IQueryable. In that case you could refine the result by using extension methods like 'Where', 'First', 'FirstOrDefault', 'Single', 'SingleOrDefault', etc. That is the only case that I can come up with, but even in those cases, if you need some kind of custom logic that would repeat you should move it to Models.
1

It can be either Controller or Model, depending on the way query is called , but if you read the question, it gives you the answer itself as it emphasize on the use of mvc pattern , which means all the data access logic is written in model , therefore the problem is in the model.

Comments

1

I think the answer should be Models, but it could be Controllers as you need to check both places really. There should be code in a Controller which calls the Model and says something like "Please give me a list of products satisfying these criterion".

It is of course possible that the code in the Controller is asking the Model for the wrong thing, of course! That's why I hate exam questions like this!

I and lots of other people tend to put this code (the Model stuff)in a Domain layer (separate project) as it is business-specific, meaning it would not change even if you changed the front end from web to winforms or whatever.

1 Comment

I hope there won't be questions like these on the real exam! Not sure if then I should answer what "they" say is correct in the practice tests or what the majority of people assumes..
0

Idealy controllers should be as lean as possible. So except small ones, writing queries to controllers is not wellcomed in my opinion. You can check The Repository Pattern to have an example.

Repository Pattern

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.