ASP. net mvc + EF framework + easyui permission management series (1)-framework construction

Source: Internet
Author: User

ASP. net mvc + EF framework + easyui permission management series (opening)

This blog begins with step by step to implement the preliminary design of this permission system-framework setup. First of all, we need to develop tools Visual Studio 2012 or 10, secondly, we need to have an SQL Server database. If it is Visual Studio 2010, you need to install the mvc4 development file. Is that true? I don't remember. Who can answer me? I always use 2012, which is integrated, so it's not clear. Because this blog is relatively simple, it just creates a simple architecture, so I will introduce the MVC knowledge by the way, and I will introduce the technologies encountered in the project in the future, next we will start our journey today.

Before learning MVC, we need to know these knowledge points (automatic attributes, implicit type var, object initializer and set initializer, Anonymous class, extension method, Lambda expression ), if you do not know, please refer to my brief introduction below. If you already know, you can go through this blog and see the initial image of the project I created below, next we will give a brief introduction.

1. Automatic attributes

(1) Automatic attributes (auto-implemented properties), C # automatic attributes can avoid manually declaring a private member variable and writing the get and set attributes.

Public class kencery // declare a kencery class

{

Public int ID {Get; set;} // primary key ID

Public string name {Get; private set;} // read-only attribute name

Public int age {Get; set;} // age

}

2. Implicit VaR

(1) now more and more projects can see var. What does this mean? In fact, this is the hermit type var provided by C #3.0. The VaR keyword instructs the compiler to deduce the variable type based on the expression on the right of the initialization statement.

VaR kencery = "Good evening"; // defines the variable

VaR list = new list <int> (); // defines a list set.

VaR kencery = new {id = 1, name = "HYL", age = 24} // type defined by object initialization

VaR geners = from N in storecontract. productcatalogs

Where n. issystem = false

Select N;

Return view (geners );

// Use of LINQ, which will be used in a lot later. If you have never learned it, you can learn it by yourself.

(2) What are the disadvantages of VaR when it has such a large function?

1) You can use VaR only when declaring and initializing a local variable in the same statement. You Cannot initialize the variable as null, method group, or anonymous method.

2) var cannot be used in the class range.

3) variables declared by VAR cannot be used in the initialization expression. In other words, this expression is legal: int I = (I = 20 );, however, the following expression produces a compilation error: var I = (I = 20 ).

4) Multiple implicit variables cannot be initialized in the same statement.

5) if there is a type named VaR in the range, the VaR keyword will be resolved to this type name, instead of being processed as part of the implicit type local variable declaration.

3. Anonymous class

(1) encapsulate a set of read-only attributes into a single object without displaying and defining a type first. The type name is generated by the compiler and cannot beSource codeClass usage. The type of each attribute is inferred by the compiler. [Var]

(2) the expression used to initialize the attribute cannot be null, anonymous function, or pointer type.

VaR kencery = new {id = 1, name = "HYL", age = 24}

4. Object initializer and set Initiator

(1) The object initializer uses the compiler to assign values to externally visible fields or attributes of the object in order, and calls the constructor in compilation or implicit mode, you can assign one or more values to a field or attribute.

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 Method

(1) The extension method is a special static method, which is defined in a static class, but can be called in the same way as the instance method is called on other class objects. Therefore, with the extension method, we can expand the function of a type without modifying a type. This method does not generate a new type, instead, the function is extended 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 storing the container of the extension method, all extension methods can be written here. The extension method is different from the declaration method of common methods. The first parameter of the extension method starts with the this keyword, followed by the extended type, and then is the real parameter list.

Public static return type Extension Method Name (this parameter name of the type to be extended [, extension method parameter list])

{

}

Public static int toint32 (this string s) // The extension method converts a string to an integer.

{

Return int32.parse (s );

}

6. Lambda expressions

(1) "Lambda expression" is an anonymous function that can contain expressions and statements and can be used to create delegates.

(2) operator =>, which is read as "goes ".

(3) Format: (input parameters) => Expression

Delegate bool deldemo (int A, int B); // defines the delegate

Deldemo Lambda = (int A, int B) => A> B // use a Lambda expression to indicate whether a is greater than B

Console. writeline (lambda (1, 4 ));

7. Overall project framework Flowchart

(1) I 've talked so much about it, but it's actually useless with our blog today. It's just some preparation work, but also a review of these knowledge points. Next we will create a new mvc4Program, How to create an mvc4 program, I believe everyone will be ready, and then set up the framework and build the framework:

(2) then we design the database at the lyzj. userlimitmvc. model layer and create an empty edmx model in it ,:

(3) We have created four class libraries and an mvc4.0 project. Let's take a closer look. If you are not clear about the role of these four class libraries, I suggest you go to the three-tier architecture or leave a message below, so you will not write it out now.

(4) This blog is over. The next blog will introduce the database access layer through interface programming.

KenceryReturn to the beginning of this series

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.