ASP.NET MVC PROJECTS
6 top level directories
- Controllers – for controller classes that handles URL requests.
- Models – for classes that represent and manipulate data .
- Views – for UI Template files that are responsible for rendering output .
- Scripts – for JavaScript(JS) library files and scripts .
- Content – for CSS/Image files and non-dynamic/non-JS content.
- App_Data – to store data files needed for read/write .
In a Model-View-Controller framework the term “model” refers to –:
- Objects that represent the data of the application .
- Corresponding domain logic that integrates validation and business rules with it.
LINQ to SQL
LINQ to SQL is an ORM (object relational mapper) that ships as part of .NET 3.5.
LINQ to SQL provides an easy way to map database tables to .NET classes we can code against.
This minimizes the amount of data code we need to write, and allows us to build really clean applications.
Schema Validation
When model classes are defined using the LINQ to SQL designer, the datatypes of the properties in the data model classes will correspond to the datatypes of the database table.
LINQ to SQL will also automatically handles escaping SQL values for you when using strings - so you don't need to worry about SQL injection attacks when using it.
For small applications it is sometimes fine to have Controllers work directly against a LINQ to SQL DataContext class, and embed LINQ queries within the Controllers. As applications get larger, though,
this approach becomes cumbersome to maintain and test. It can also lead to us duplicating the same LINQ queries in multiple places.
One approach that can make applications easier to maintain and test is to use a “repository” pattern.
A repository class helps encapsulate data querying and persistence logic, and abstracts away the implementation details of the data persistence from the application.
In addition to making application code cleaner, using a repository pattern can make it easier to change data storage implementations in the future, and it can help facilitate unit testing an application without requiring a real database.