Oo learning Summary: 1. System Software Architecture-Change Response

Source: Internet
Author: User
During the development process, it is normal for the system or even the data structure to change. We can reduce the number, but we cannot avoid it. It provides us with a simple method. 1.3 one of the responses to changes: additional operation methods

Further operations are often required in the actual needs of the project. For example, a query is performed based on a field that is not a primary key. At this time, you need to use the form of SQL statements (you can also use the stored procedure, recommended SQL method, good debugging ).

The following example adds a query for a field:

Method 1: Build a new method

You need a method to query a field, which is not the primary key:

1. First, add an SQL string in the constant section.

// According to the user code,

Private const string SELECT_ONE_ SQL _bypisfield199 = "SELECT * FROM JQ0 WHERE pisfield199 = ";

2. Add a new method.

/// <Summary>

/// Return records based on user Encoding

/// </Summary>

/// <Param name = "wISFIELD000"> </param>

/// <Returns> an item </returns>

Public IList <JQ0Entity> GetJQ0byPISFIELD199 (string PISFIELD199)

{

String querystring = SELECT_ONE_ SQL _bypisfield199;

Querystring + = "'" + PISFIELD199 + "'";

Return GetJQ0sbyQueryString (querystring );

}

3. Add the method to IDAL and BLL in sequence.

Method 2: directly input the query string

You can directly call the method without adding a new method for simple query.

GetLDJQ0sbyQueryString (string sqlstr)

Note:

The specific method is used. Based on the complexity of the task to be performed, if there are many operations such as judgment and comparison, a new method can be added for operations that cannot be completed by a statement.

1.4 Response to changes 2: field changes

During development, fields in the data table may change, including adding fields, changing the length and type. The corresponding MODEL and DAL layers need to be regenerated. The corresponding BLL and IDAL may also need to be generated. In this way, the methods added during the development process will be washed out and need to be copied back. Or use the partial class distribution class. The partial type allows us to write the description of a class in different places, or even to two or more different files. The partial information is only useful to the compiler. during compilation, the compiler will see that the description of a class is "broken" (partial), and it will collect other fragments of the class elsewhere, then combine all the fragments of the class into a complete class and compile it.

In BLL, IDAL, and DAL, we divide all the generated classes into two files. One file is the file corresponding to the original template, which is called the basic file. The other is an additional file.

 


After the basic file is generated, it will not be changed, and subsequent changes will be made in the attached file. When the structure of the data table changes, you can regenerate the basic file.

 



Note: add methods in the attached file.

The New DAL layer structure is as follows:

 


The default DAL *** ADD. cs file has only one blank partial class structure, waiting for a new method to be added during development.

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.