All articles in this series index: CYQ. Data lightweight Data layer path framework open-source series Index
All related downloads in this series: CYQ. Data lightweight Data layer-path bug feedback, optimization suggestions, and latest framework downloads
Preface:
I have been writing articles only after publishing a version. This time, I will give a brief introduction to the preemptible version [V2.5 ].
The following is a description of function updates [compared with V2.0]:
1: fixed the problem that the DebugInfo attribute could not obtain the operation statement when an exception occurred.
2: The Bind method added to MAction allows you to easily Bind controls such as DropDownList.
3: added the ToList <T> generic method to the MDataTable.
4: corrected the ToJson method of MDataTable. 5: added the abstract base class CYQ. Data. Orm. OrmBase [to support traditional real-size ORM]
Next, perform an example operation for the function. All the code is written in Page_Load.:
I. debugging information output
1: Write the following code:
MAction action = new MAction (TableNames. Users );
If (! Action. Fill ("generate error "))
{
Response. Write (action. DebugInfo );
}
2: An exception is thrown by default.
3: modify the configuration file and enable logging. No exception is thrown.
<Shortettings> <add key = "IsWriteLog" value = "true"/> </shortettings>
4: run again at this time and output DebugInfo
Note:
You can see the SQL statements executed by all databases for easy debugging.
Ii. Demonstration of the Bind function of MAction
1: Write the following code:
New MAction (TableNames. Users). Bind (ddlUserName). Close ();
Note:
The Bind method has three overload methods:
Public MAction Bind (object control)
Public MAction Bind (object control, string where)
Public MAction Bind (object control, string where, object text, object value)
Note: The preceding two methods use the [control id (remove the three letter prefix) as the text field + the ID is the value field] The control parameter can inherit all controls of ListControl, for example: drowDownList/CheckBoxList/RadioButtonList
2: Demo result
3: Corresponding html
<Select name = "ddlUserName" id = "ddlUserName">
<Option value = "1"> passing by autumn </option>
<Option value = "2"> wolf Robot </option>
<Option value = "3"> Deep Blue doctor </option>
<Option value = "4"> 123 days </option>
<Option value = "5"> 123444 days </option>
<Option value = "9"> goodboy </option>
<Option value = "17"> goodboy </option>
</Select>
3. demo of the MDataTable ToList <T> Method
1: add the entity Users
UsersDemo entity class
Public class UsersDemo
{
Private int _ ID;
Public int ID
{
Get
{
Return _ ID;
}
Set
{
_ ID = value;
}
}
Private string _ Username;
Public string UserName
{
Get
{
Return _ Username;
}
Set
{
_ Username = value;
}
}
Private string _ Password;
Public string Password
{
Get
{
Return _ Password;
}
Set
{
_ Password = value;
}
}
Private DateTime _ CreateTime;
Public DateTime CreateTime
{
Get
{
Return _ CreateTime;
}
Set
{
_ CreateTime = value;
}
}
}
2. Write the following code:
MAction action = new MAction (TableNames. Users );
MDataTable table = action. Select ();
Action. Close ();
List <UsersDemo> listDemo = table. ToList <UsersDemo> (); // convert it to a List of generic entities
GvUsers. DataSource = listDemo;
GvUsers. DataBind ();
3: Demo result
4. demo of the ToJson method of MDataTable
1: Write the following code:
Using (MAction action = new MAction (TableNames. Users ))
{
Response. Write (action. Select (). ToJson ());
}
2: output results
{"Count": "7", "error": "", "success": "true ",
"Data": [{"ID": "1", "UserName": "fall by", "Password": "http://cyq1162.cnblogs.com", "CreateTime ": "14:01:07 "},
{"ID": "2", "UserName": "Wolf Robot", "Password": "http://cyq1162.cnblogs.com", "CreateTime": "14:04:57 "},
{"ID": "3", "UserName": "", "Password": "http://cyq1162.cnblogs.com", "CreateTime": "14:05:44 "},
{"ID": "4", "UserName": "Genius 123", "Password": "http://cyq1162.cnblogs.com", "CreateTime": "14:57:28 "},
{"ID": "5", "UserName": "Genius 123444", "Password": "http://cyq1162.cnblogs.com", "CreateTime": "15:00:20 "},
{"ID": "9", "UserName": "goodboy", "Password": "abc", "CreateTime": "16:51:58" },{ "ID ": "17", "UserName": "goodboy", "Password": "333", "CreateTime": "17:09:34"}]}
V. demo of support for traditional ORM access
Note: This function is triggered by messages from the anchor.
Reference
Paladin: Oh, it was the first time you came here to support it! It would be better if your lightweight data layer framework supports both ORM and traditional access!
1: The entity inherits CYQ. Data. Orm. OrmBase
Public class UsersDemo: CYQ. Data. Orm. OrmBase
{
Public UsersDemo ()
{
Base. SetInit (this, "Users", "Conn ");
}
//... Omitting the object attribute of the lower area
}
Note:
1: The base class CYQ. Data. Orm. OrmBase needs to be inherited.
2: You need to initialize base. SetInit (this, "table name", "database link string/Link Configuration name/if it is null, It is the Conn configuration item by default") in the constructor ");
2: Compile the code to demonstrate [Add/update/delete/query/list query and binding]
Protected void Page_Load (object sender, EventArgs e)
{
UsersDemo myUser = new UsersDemo ();
MyUser. UserName = "passing by autumn-blog Garden ";
MyUser. Password = "http://cyq1162.cnblogs.com ";
MyUser. Insert (); // Insert a data entry
MyUser. Password = "I changed the Password ";
MyUser. Update ();
MyUser. Delete (17); // Delete data with id = 17
If (myUser. Fill (9) // Fill in a single data
{
Response. Write (myUser. UserName );
}
MyUser. Select (). Bind (gvUsers); // query all data in the Users table and Bind it to the GrivdView Control
List <UsersDemo> entityList = myUser. Select (). ToList <UsersDemo> ();
GvUsers2.DataSource = entityList; // bind to the generic type
GvUsers2.DataBind ();
}
3: Result demonstration
A: original table data
B: operation result data
Statement:
Thank you for your support and support. I will continue to update the Framework.