Preface: This article starts with step-by-step implementation of this permission system's preliminary design-framework construction, first of all, I would like to say that we need to develop tools visual Studio 2012 or 10 is OK, followed by we want to have a SQL Server database, if it is Visual Studio 2010, you also have to install MVC4 development file, this is? I do not remember, who can answer me, I have been using 2012, are integrated well, so it is not clear. Because this blog is relatively simple, just to build a simple architecture, so I have to do with the knowledge of MVC, I will also be interspersed with the introduction of the technology encountered in the project, the following start today's trip.
1. Automatic properties
(1) Automatic attributes (auto-implemented properties), C # Automatic properties can avoid the original we manually declare a private member variable as well as and attribute Get,set writing.
Copy Code code as follows:
public class Kencery//declaration of a Kencery class
{
public int id{get;set;} Primary Key ID
public string name{get;private set; Read-only property name
public int age{get;set;} Age
}
2. implicitly-typed Var
(1) Now more and more projects you can see VAR, what does this mean? In fact, this is the hermit type that c#3.0 's new feature provides. The Var,var keyword instructs the compiler to infer the type of the variable based on an expression to the right of the initialization statement.
Copy Code code as follows:
var kencery= "Good evening for everyone"; Defining variables
var list=new list<int> (); Define a list collection
var kencery=new{id=1,name= "Hyl", age=24}//object initialization defined type
var geners = from N in storecontract.productcatalogs
where N.issystem = = False
Select N;
Return View (geners);
The use of LINQ, this in the back we will be a lot of use, we have not learned to self-study.
(2) var has such a large function, then he has any shortcomings, we are here to enumerate roughly
1 You can use VAR only if you declare and initialize a local variable in the same statement, you cannot initialize the variable to null, a method group, or an anonymous method.
2 cannot use VAR for class-scoped domains.
3 A variable declared by VAR cannot be used in an initialization expression, in other words, the expression is legal: int i= (I=20), but the following expression produces a compilation error: Var i= (i=20).
4 cannot initialize multiple implicitly typed variables in the same statement.
5 If the range has a type named Var, the var keyword resolves to the type name and does not work as part of the implicit type local variable declaration.
3. Anonymous class
(1) Encapsulates a set of read-only properties into a single object without first showing the definition of a type, the type name is generated by the compiler, and cannot be used at the source code level, and the type of each property is inferred by the compiler. [Var]
(2) The expression used to initialize the property cannot be null, an anonymous function, and a pointer type.
var kencery=new{id=1,name= "Hyl", age=24}
4. Object initializers and collection initializers
(1) The object initializer uses the compiler to assign values to fields or properties that are externally visible in the object, and the constructor is either compiled or implicitly called, and the assignment to a field or property can be one or more.
Copy Code code as follows:
List<kencery> kencery=new list<kencery>{//kencery class
New Kencery{id=1,name= "Hanyinglong", age=19},
New kencery{id=2,name= "Hyl"},
Null
};
Person p=new person{id=1,name= "Hyl", age=19};
5. Extension methods
(1) An extension method is a special static method that is defined in a static class, but can be invoked on an object of another class to the calling instance method. Thus, by extending the method, we can extend the function of a type without modifying a type, which does not produce new types, but rather extends the functionality by adding new methods to existing classes.
(2) When extending an existing class, we need to write all the extension methods in a static class, which is equivalent to the container where the extension method is stored, and all extension methods can be written in this area. Extension methods are different from normal methods, the first parameter of the extension method starts with the This keyword, followed by the extended type, and then the real argument list.
Copy Code code as follows:
public static return type extension method name (this is the type parameter name to extend [, extension method argument list])
{
}
public static int ToInt32 (this string s)//extension method converts a string to an integer
{
Return Int32.Parse (s);
}
6. Lambda expression
(1) "Lambda expression" is an anonymous function that can contain expressions and statements that can be used to create delegates.
(2) operator =>, the operator reads: "Goes to".
(3) Format: (Input parameters) =>expression
delegate bool Deldemo (int a,int b); Defining delegates
Deldemo lambda= (int a,int b) =>a>b//using a LAMBDA expression to indicate whether a is greater than B
Console.WriteLine (Lambda (1,4));
7. Project Overall frame flowchart
(1) There's so much on it, in fact, with our blog today is no use, just a few preparations, but also to review these knowledge points, we will create a new MVC4 program, how to create a new MVC4 program, I believe we have already, and then build the framework, the framework as shown in the picture:
(2) Then we LYZJ.UserLimitMVC.Model the database and create an empty EDMX model in it, as shown in the figure:
(3) above we have established four class libraries and a MVC4.0 project, we look carefully, if the role of these four libraries is not very clear, I suggest you can go to see the three-tier structure, or in the following message to me, now do not write out.
(4) This blog is over here, the next blog we start to talk about: the use of interface programming into the database access layer to introduce.