1           概览

l  Models . Model objects are the parts of the application that implement the logic for the application s data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in SQL Server.

modeldata的区别与联系.

Ø  Business logic belongs in the model.

Ø 

 

 

l  Views . Views are the components that display the application s user interface (UI). Typically, this UI is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Products object.

l  Controllers . Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn queries the database by using the values.

MVC 优点:

The MVC pattern helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic.

 

MVC 执行周期 :

Stage

Details

Receive first request for the application

In the Global.asax file, Route objects are added to the RouteTable object.

Perform routing

The UrlRoutingModule module uses the first matching Route object in the RouteTable collection to create the RouteData object, which it then uses to create a RequestContext object.

Create MVC request handler

The MvcRouteHandler object creates an instance of the MvcHandler class and passes the RequestContext instance to the handler.

Create controller

The MvcHandler object uses the RequestContext instance to identify the IControllerFactory object (typically an instance of the DefaultControllerFactory class) to create the controller instance with.

Execute controller

The MvcHandler instance calls the controller's Execute method.

Invoke action

For controllers that inherit from the ControllerBase class, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.

Execute result

The action method receives user input, prepares the appropriate response data, and then executes the result by returning a result type. The built-in result types that can be executed include the following: ViewResult (which renders a view and is the most-often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.

 

 Language Integrated Query (LINQ)

参考:http://social.msdn.microsoft.com/search/en-us?query=LINQ&x=0&y=0

 

class QueryVMethodSyntax
{
static void Main()
{
int[] numbers = { 5, 10, 8, 3, 6, 12};

//Query syntax:
IEnumerable< int> numQuery1 =
from num in numbers
where num % 2 == 0
orderby num
select num;

//Method syntax:
IEnumerable< int> numQuery2 = numbers.Where(num => num % 2 == 0).OrderBy(n => n);

foreach ( int i in numQuery1)
{
Console.Write(i + " ");
}
Console.WriteLine(System.Environment.NewLine);
foreach ( int i in numQuery2)
{
Console.Write(i + " ");
}

// Keep the console open in debug mode.
Console.WriteLine(System.Environment.NewLine);
Console.WriteLine( "Press any key to exit");
Console.ReadKey();
}
}

Lambda Expressions    

http://msdn.microsoft.com/enus/library/bb397687.aspx 

http://www.cnblogs.com/JeffreyZhao/archive/2009/08/07/from-delegate-to-others-2.html

Note in the previous example that the body of an expression lambda can consist of a method call. However, if you are creating expression trees that will be consumed in another domain, such as SQL Server, you should not use method calls in lambda expressions. The methods will have no meaning outside the context of the .NET common language runtime.

Linq to  Sql   http://msdn.microsoft.com/en-us/library/bb399398.aspx

 

 
  
  1.  
  2. // Northwnd inherits from System.Data.Linq.DataContext.  
  3. Northwnd nw = new Northwnd(@"northwnd.mdf");  
  4. // or, if you are not using SQL Server Express  
  5. // Northwnd nw = new Northwnd("Database=Northwind;Server=server_name;Integrated Security=SSPI");  
  6.  
  7. var companyNameQuery =  
  8.     from cust in nw.Customers  
  9.     where cust.City == "London" 
  10.     select cust.CompanyName;  
  11.  
  12. foreach (var customer in companyNameQuery)  
  13. {  
  14.     Console.WriteLine(customer);  
         

 

总结: