CYQ. The path to the lightweight Data layer of Data continues to be enthusiastically upgraded (III)

Source: Internet
Author: User

In the previous article: CYQ. Data lightweight Data layer ultimate upgrade (II), I added the GetFrom and SetTo methods to avoid the inconvenience of directly using index values and assigning values.

 

Originally, today I plan to write an instance tutorial to briefly introduce how easy it is to use this ultra-Lightweight Framework for Development. However, some small bugs are found during use.

As a result, today I am excited about modifying N multi-code, extracting SQL components into a separate class, and removing N multi-overload methods, leaving the most concise and practical method.

 

Let's take a look at the improvements:

The database configuration is assumed as follows:

<ConnectionStrings>
<Add name = "Conn" connectionString = "Server =., database = CQSpace; uid = sa; pwd = 123456"/>
<Add name = "CYQ" connectionString = "Server =., database = CQSpace; uid = sa; pwd = 123456"/>
</ConnectionStrings>

 

Operation instance method:

Method 1: The Link string of the configuration file Conn is used by default.

MAction action = new MAction (TableNames. CQ_BlogSet );

Method 2: Use a link string with a definition name such as CYQ:

MAction action = new MAction (TableNames. CQ_BlogSet, "CYQ ");

 

Method 3: directly retrieve the link string

MAction action = new MAction (TableNames. CQ_BlogSet, "Server =.; database = CQSpace; uid = sa; pwd = 123456 ");

 

 

Next, let's take a look at the operation method updates:

1: single data query method:

Method 1: directly upload ID

MAction action = new MAction (TableNames. CQ_BlogSet );
If (action. Fill (888 ))
{
Action. SetTo (lblAlbumType );
Action. Close ();
}

 

Method 2: Pass the where Condition

MAction action = new MAction (TableNames. CQ_BlogSet );
If (action. Fill ("Title = 'xxxx '"))
{
Action. SetTo (lblAlbumType );
Action. Close ();
}

 

 

2: data deletion:

Method 1: first fill and then delete

If (action. Fill (888 ))
{
Action. Delete ();
Action. Close ();
}

 

Method 2: delete by ID

MAction action = new MAction (TableNames. CQ_Album );
Action. Delete (888 );
Action. Close ();

 

Method 3: delete based on conditions

MAction action = new MAction (TableNames. CQ_Album );
Action. Delete ("id> 888 ");
Action. Close ();

 

3: Data Update

Method 1: first fill and then update

MAction action = new MAction (TableNames. CQ_Album );
If (action. Fill (111 ))
{
Action. GetFrom (txtAlbumName );
Action. Update ();
Action. Close ();
}

 

Method 2: update by ID

MAction action = new MAction (TableNames. CQ_Album );
Action. GetFrom (txtAlbumName );
Action. Update (1, 111 );
Action. Close ();

 

Method 3: update based on conditions

MAction action = new MAction (TableNames. CQ_Album );
Action. GetFrom (txtAlbumName );
Action. Update ("id = 299 or name = 'Passing by autumn '");
Action. Close ();

 

4: The data list query and multi-table joint query remain unchanged.

See section 1: CYQ. Data lightweight Data layer (1)

5: New count query:

MAction action = new MAction (TableNames. CQ_BlogSet );
LblAlbumType. Text = action. GetCount ("id> 2 and Name = ' '"). ToString ();
Action. Close ();

 

 

6: The Get and Set methods are generated to further hide the value and value assignment of the index:

During the upgrade in the previous section, the newly added GetFrom and SetTo operations can only assign values to controls. What if we only need values or set values without controls in the middle?

Before the preceding section, we can only return to the index method. The values are as follows:

String albumType = action. Data [CQ_Album.AlbumName]. Value. ToString ();

After an avid upgrade: with the newly added Get method, the effect becomes:

String albumType = action. Get <string> (CQ_Album.AlbumName );

The value assigned by the Set method is:

Action. Set (CQ_Album.AlbumName, "passing by autumn ";);

 

 

Therefore, we currently have three methods available for value and Value assignment:

 

1: For controls: GetFrom and SetTo

2: Get and Set for variable type

3: Reserved: index data/enumeration and field name (string) Values

 

 

 

OK. This section introduces the example application. Welcome to use and leave a message!

Finally, the new version V1.2 is available for download. Click to download [size: 60 K unencrypted, unlimited, and unrestricted. You can directly use reflector.exe to view the source code]

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.