前言:
由于上一版本過于穩定,導緻此版本無bug修正項,但是新增了幾個重要的性能優化功能。
本版本新增加的功能預覽
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
1:優化access、sqlite資料庫連結,以{0}代表根目錄
好處:可以配置多個資料庫連結,示例如:秋色園qblog同時用了n個access資料庫。
2:maction增加指定列的查詢功能:setselectcolumns
好處:查詢時可以指定列名,減少傳輸量。
3:增加appdebug類,可以全局輸出執行過的sql語句
好處:随時掌控并列印頁面sql,直接分析和優化sql語句
4:增加fasttot的emit類,提升大資料量時從mdatatable轉list<t>的性能
好處:在傳回資料量較大轉實體時,可以利用emit加快速度,提升性能。
5:關閉預設mssql/oracle的事務開啟
好處:事務有需要就打開,預設不打開。
如需要相容v4.5及以前版本的事務,可使用配置項相容:<add key="transationdefaultopen" value="true"> </add>
6:xmlhelper更名為xhtmlaction
其它:增加的配置項:
opendebuginfo:true/false,是否開啟調試sql語句記錄,開發時打開,運作時可關閉。
recordsqllongquerytime:n(機關毫秒),運作時設定,記錄執行時間長的sql語句,可以針對性分析與優化。
appdebugfiltertime:n(機關毫秒),appdebug可以輸出頁面sql,通過此項可以過濾。
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
下面進行詳細的解說
示例:
<connectionstrings>
<add name="conn" connectionstring="data source={0}app_data\qblog.db;failifmissing=false" providername="system.data.sqlite" />
</connectionstrings>
示例:[包含:查詢,分頁,綁定]
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
protected void binddata()
{
int count;
using (maction action = new maction(tablenames.blog_class))
{
action.setselectcolumns(selectcolumns);//指定列
action.select(pager1.pageindex, pager1.pagesize, string.empty, out count).bind(gvclass);
pager1.count = count;
pager1.bindname = "binddata";
}
}
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
示例:[在頁面基類裡,輕松處理一下即可]
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
public class pagebase:system.web.ui.page
{
protected override void oninit(eventargs e)
appdebug.start();//開啟記錄頁面的sql
base.oninit(e);
protected override void onprerendercomplete(eventargs e)
base.onprerendercomplete(e);
response.write(appdebug.info);//輸出記錄頁面的sql
appdebug.stop();//停止記錄頁面的sql
}
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
頁面效果:
這裡直接放上我研究n天的源碼,不過能看懂的估計也毛毛無幾,能用上的直接拿去用了:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
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>
/// 快速轉換類[資料量越大[估約500條起],性能越高]
/// </summary>
internal class fasttot<t>
{
public delegate t emithandle(mdatarow row);
/// <summary>
/// 建構一個orm實體轉換器
/// </summary>
/// <typeparam name="t">轉換的目标類型</typeparam>
/// <param name="schema">表資料架構</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值,跳過
gen.emit(opcodes.ldloc_0);
emitcastobj(gen, field.fieldtype);
gen.emit(opcodes.stfld, field);
gen.marklabel(retfalse);//繼續下一個循環
}
}
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);
}
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
其它幾點的示例,寫成了示例項目:
示例解決方案:
完整的示例頁面:
最後:
版權聲明:本文原創發表于部落格園,作者為路過秋天,原文連結:
http://www.cnblogs.com/cyq1162/archive/2011/08/13/2136911.html