1

Quick question about database views. Am I right in assuming that I can create a database of view of various tables and connect them how I want etc and then when I do queries, add, edit delete etc then MVC will figure it all out for me without needing to do any complex SQL in the controller or repository?

Odd question but just wanted to make sure my assumption was valid. Cheers

3 Answers 3

1

Unfortunately, MVC will not figure it all out for you, you'll still need to write the SQL code (or use an ORM framework) to communicate with the database.

What MVC gives you with it's architecture is a clear separation of responsibilities:

  • Views are responsible for displaying data and should be as simple as possible (i.e. little to no logic in them)

  • Model(s) contain the business logic and rules

  • Controllers are responsible for passing data between the Model and the Views.

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

2 Comments

I will still have the SQL grabbing what I want. But i mean I don't need to do any joins or anything as the database view will handle it right?
The Database view will take care of the joins (assuming it's set up correctly). As far as I know though, most databases will error if you try to INSERT/UPDATE/DELETE data in a view, as it is as the name implies, a view of the data (i.e. READ operations) and nothing more.
1

What you are looking for is Scaffolding. In .net MVC I can't think of any tools which do this for you directly against the database. They all require either as Russ said an ORM i.e. Linq To SQL or Entity Framework (EF).

http://msdn.microsoft.com/en-us/library/cc488540.aspx

The closest you could get would be to use Database First model generation and then put the necessary MVC templates/views/code on top.

Comments

0

A database view is read-only so you will not be able to perform write operations on the view. You can however create a model from a view and display your data as defined from the view. If you are using an ORM solution such as ADO.NET Entities you can instantiate an object and add the child objects to it and be able to save the final result in a single transaction as well.

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.