Preface:
Following the previous version: CYQ. Data framework V4.5 was released. It has been refreshing for more than three months,
Further, it has been more than half a year since the release of CYQ. Data V4.5. Today, we have to release a new minor version.
Because the previous version was too stable, this version had no bug fixes, but added several important performance optimization functions.
New features of the current version are previewed.
1: optimized Access and SQLite database links, with {0} representing the root directory
Benefit: You can configure multiple database links. For example, you have used N access databases at the same time in QBlog of the autumn color garden.
2: MAction adds the query function of the specified column: SetSelectColumns
Benefit: You can specify a column name during query to reduce the transmission volume.
3:Added the AppDebug class to output SQL statements that have been executed globally.
Benefits: You can control and print Page SQL statements at any time, and analyze and optimize SQL statements directly.
4: added the FastToT Emit class to Improve the Performance of migrating data from MDataTable to List <T> when the data volume is large.
Benefits: Emit can be used to speed up and improve performance when the returned data volume is large to convert objects.
5: Disable mssql/oracle transaction enabling by default
Benefit: the transaction is opened as needed, but is not opened by default.
To be compatible with transactions of V4.5 and earlier versions, use the configuration items:<Add key = "TransationDefaultOpen" value = "true"> </add>
6:XmlHelper is renamed as XHtmlAction
Others:Added configuration items:
OpenDebugInfo: true/false: whether to enable the SQL statement record debugging. It is enabled during development and can be disabled during runtime.
RecordSqlLongQueryTime: N (unit: milliseconds). It is set at run time to record SQL statements that have been executed for a long time, which can be analyzed and optimized in a targeted manner.
AppDebugFilterTime: N (unit: milliseconds). AppDebug can output Page SQL statements, which can be used to filter.
The following is a detailed explanation.
1: optimized Access and SQLite database links, with {0} representing the root directory
Example:
<ConnectionStrings>
<Add name = "Conn" connectionString = "Data Source = {0} App_Data \ qblog. db; failifmissing = false" providerName = "System. Data. SQLite"/>
</ConnectionStrings>
2: MAction adds the query function of the specified column: SetSelectColumns
Example: [Include: Query, paging, binding]
Protected void BindData ()
{
Int count;
Using (MAction action = new MAction (TableNames. Blog_Class ))
{
Action. SetSelectColumns (selectColumns); // specifies the column
Action. Select (Pager1.PageIndex, Pager1.PageSize, string. Empty, out count). Bind (gvClass );
Pager1.Count = count;
Pager1.BindName = "BindData ";
}
}
3: added the AppDebug class to globally output executed SQL statements.
Example: [In the page base class, you can easily handle it]
Public class PageBase: System. Web. UI. Page
{
Protected override void OnInit (EventArgs e)
{
AppDebug. Start (); // enable the SQL statement on the record page
Base. OnInit (e );
}
Protected override void OnPreRenderComplete (EventArgs e)
{
Base. OnPreRenderComplete (e );
Response. Write (AppDebug. Info); // The SQL statement of the output record page
AppDebug. Stop (); // Stop the SQL statement on the record page
}
}
Page effect:
4: added the FastToT Emit class to Improve the Performance of migrating data from MDataTable to List <T> when the data volume is large.
Here I put the source code for my study for N days, but I can understand the estimation is not much, I can use it directly:
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Reflection. Emit;
Using System. Reflection;
Using CYQ. Data. Table;
Namespace CYQ. Data. Tool
{
/// <Summary>
/// Quick conversion class [the larger the data volume [about 500], the higher the performance]
/// </Summary>
Internal class FastToT <T>
{
Public delegate T EmitHandle (MDataRow row );
/// <Summary>
/// Construct an ORM entity Converter
/// </Summary>
/// <Typeparam name = "T"> target type of conversion </typeparam>
/// <Param name = "schema"> table data architecture </param>
Public static EmitHandle Create (MDataTable schema)
{
Type tType = typeof (T );
Type rowType = typeof (MDataRow );
DynamicMethod method = new DynamicMethod ("RowToT", tType, new Type [] {rowType}, tType );
MethodInfo getValue = rowType. GetMethod ("GetItemValue", BindingFlags. Instance | BindingFlags. Public | BindingFlags. NonPublic, null, new Type [] {typeof (int)}, null );
ILGenerator gen = method. GetILGenerator ();
Gen. DeclareLocal (tType );
Gen. DeclareLocal (typeof (object ));
Gen. DeclareLocal (typeof (bool ));
Gen. Emit (OpCodes. Newobj, tType. GetConstructor (BindingFlags. Instance | BindingFlags. Public | BindingFlags. NonPublic, null, new Type [] {}, null ));
Gen. Emit (OpCodes. Stloc_0 );
Int ordinal =-1;
Foreach (FieldInfo field in tType. GetFields (BindingFlags. Instance | BindingFlags. NonPublic | BindingFlags. Public ))
{
String fieldName = field. Name. TrimStart ('_');
Ordinal = schema. GetOrdinal (fieldName );
If (ordinal>-1)
{
Label retFalse = gen. DefineLabel ();
Gen. Emit (OpCodes. Ldarg_0 );
Gen. Emit (OpCodes. Ldc_I4, ordinal );
Gen. Emit (OpCodes. Call, getValue );
Gen. Emit (OpCodes. Stloc_1 );
Gen. Emit (OpCodes. Ldloc_1 );
Gen. Emit (OpCodes. Ldnull );
Gen. Emit (OpCodes. Ceq );
Gen. Emit (OpCodes. Stloc_2 );
Gen. Emit (OpCodes. Ldloc_2 );
Gen. Emit (OpCodes. Brtrue_S, retFalse); // null value, skip
Gen. Emit (OpCodes. Ldloc_0 );
Gen. Emit (OpCodes. Ldloc_1 );
EmitCastObj (gen, field. FieldType );
Gen. Emit (OpCodes. stdes, field );
Gen. MarkLabel (retFalse); // continue the next loop
}
}
Gen. Emit (OpCodes. Ldloc_0 );
Gen. Emit (OpCodes. Ret );
Return method. CreateDelegate (typeof (EmitHandle) as EmitHandle;
}
Private static void EmitCastObj (ILGenerator il, Type targetType)
{
If (targetType. IsValueType)
{
Il. Emit (OpCodes. Unbox_Any, targetType );
}
Else
{
Il. Emit (OpCodes. Castclass, targetType );
}
}
}
}
Other examples are written as example projects:
Example solution:
Complete Example page:
Finally:
CYQ. Data framework home: http://www.cyqdata.com/cyqdata
CYQ. Data framework download (including examples): http://www.cyqdata.com/download/article-detail-426