﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-Teddy's Knowledge Base</title><link>http://www.cnblogs.com/teddyma/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 09 Jul 2008 13:17:14 GMT</lastBuildDate><pubDate>Wed, 09 Jul 2008 13:17:14 GMT</pubDate><ttl>60</ttl><item><title>一种高性能Hierarchical RBAC实现方案</title><link>http://www.cnblogs.com/teddyma/archive/2008/01/23/1050627.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Wed, 23 Jan 2008 13:29:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2008/01/23/1050627.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/1050627.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2008/01/23/1050627.html#Feedback</comments><slash:comments>23</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/1050627.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/1050627.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">背景</SPAN><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框图</SPAN></P>
<P><IMG height=202 alt=h_rbac.GIF src="http://www.cnblogs.com/images/cnblogs_com/teddyma/h_rbac.GIF" width=396 border=0><BR></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上图中，</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和被设置</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">都是可以有任意层级继承关系的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">举例</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">举一个网站的例子来说：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果，</SPAN><SPAN lang=EN-US>User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示网站用户；</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示角色；</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表示所有可访问的</SPAN><SPAN lang=EN-US>URL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">；</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是对每一个</SPAN><SPAN lang=EN-US>URL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的某一个权限（如：查看，修改等）。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以有任意层级继承关系，如：用户角色可以分为</SPAN><SPAN lang=EN-US>Normal User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Admin User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>Admin User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下又可以分为</SPAN><SPAN lang=EN-US>Super Admin</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>Content Admin</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>Support Admin</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>URL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这种</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也可以有任意层级继承关系的，如：对</SPAN><SPAN lang=EN-US><A href="http://abc.com/A/A1/A11/A111.aspx">http://abc.com/A/A1/A11/A111.aspx</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这样一个链接，可以认为</SPAN><SPAN lang=EN-US><A href="http://abc.com/A1">http://abc.com/A1</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个</SPAN><SPAN lang=EN-US>URL Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US><A href="http://abc.com/A/A1/A11">http://abc.com/A/A1/A11</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是他的一个子</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US><A href="http://abc.com/A/A1/A11/A111.aspx">http://abc.com/A/A1/A11/A111.aspx</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">又是</SPAN><SPAN lang=EN-US><A href="http://abc.com/A/A1/A11">http://abc.com/A/A1/A11</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的一个子</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对某一个</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来说，他对某一个</SPAN><SPAN lang=EN-US>Resource – R1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的具体的</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，等于关联到这个</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Resource - R1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">及其所有父级</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的并集。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于某一个</SPAN><SPAN lang=EN-US>User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来说，他对某一个</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，等于他所属的所有</SPAN><SPAN lang=EN-US>Roles</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的并集。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">问题</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">各元素之间的关系容易理解，关键的难点在于，因为</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">都可以是有无限层级继承关系的，如何保证权限信息验证具有较高的性能呢？当继承关系较复杂时，递归检测的性能无疑是不可接受的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据库表</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>Name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>Name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>ParentID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US>LeftIndex</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>RightIndex</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>UsersInRoles</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US>UserID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>RoleID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>Name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>ParentID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US>LeftIndex</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>RightIndex</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>PermissionsOfRole</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US>PermissionsValue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>ResourceID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>RoleID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里简单起见，对于</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，使用一个二进制位表示一个具体的</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。我们需要事先定义一个</SPAN><SPAN lang=EN-US>PermissionsValue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的每一个二进制位表示的</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。例如：如果</SPAN><SPAN lang=EN-US>PermissionsValue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的二进制值为</SPAN><SPAN lang=EN-US>10101010</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，表示从低位到高位第</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>6</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位所代表的权限的并集。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用二进制位表示一个具体的</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的好处是，处理</SPAN><SPAN lang=EN-US>Permissions</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的并操作可以转换为二进制的</SPAN><SPAN lang=EN-US>OR</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">；缺点是，具体的</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">想不能特别多，因为多一个就意味着</SPAN><SPAN lang=EN-US>PermissionsValue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的最大值大一个</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的次方。</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位二进制的最大值是</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">次方，这不算很大，但是，</SPAN><SPAN lang=EN-US>1000</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位二进制的最大值是</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>1000</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">次方，这就是个不可想象的巨大数字了。好在，一般来讲，具体的</SPAN><SPAN lang=EN-US>Permission</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">项目不会特别多的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">该方案的关键，就在于</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表的</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这两个字段了，我们将使用这两个字段，在避免递归的情况下，实现较高性能的取某个继承节点的所有子元素或所有父元素的算法。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">算法</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们以</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为例，首先</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表中有且只有一条记录存放所有</SPAN><SPAN lang=EN-US>Roles</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的顶层父节点（</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，“</SPAN><SPAN lang=EN-US>Root Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”，</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。当他没有子节点时，其</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值分别为</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。当对其插入子节点时，</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值需要做相应的调整，调整的规则如下（括号中为</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值）：</SPAN></P>
<P><IMG height=199 alt=h_rbac_alg.GIF src="http://www.cnblogs.com/images/cnblogs_com/teddyma/h_rbac_alg.GIF" width=373 border=0><BR></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按逆时针方向，大家能看出规则吗？</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按照这个规则，我们可以如下获取某一个节点的所有字节点或所有父结点（使用伪</SPAN><SPAN lang=EN-US>SQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码表示）：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">获取</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>3</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">节点的所有的子结点包括本身：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT * FROM Role WHERE <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">LeftIndex &gt;= (SELECT LeftIndex FROM Role WHERE ID = 3)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">AND<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">RightIndex &lt;= (SELECT RightIndex FROM Role WHERE ID = 3)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注：如果要不包括</SPAN><SPAN lang=EN-US>ID=3</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的节点本身，只需要用</SPAN><SPAN lang=EN-US>&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>&lt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代替</SPAN><SPAN lang=EN-US>&gt;=</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>&lt;=</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">获取</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">节点的所有父节点包括本身：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT * FROM Role WHERE<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">LeftIndex &lt;= (SELECT LeftIndex FROM Role WHERE ID = 3)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">AND<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">RightIndex &gt;= (SELECT RightIndex FROM Role WHERE ID = 3)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注：如果要不包括</SPAN><SPAN lang=EN-US>ID=5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的节点本身，只需要用</SPAN><SPAN lang=EN-US>&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>&lt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代替</SPAN><SPAN lang=EN-US>&gt;=</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>&lt;=</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家可以根据上面的图验证一下算法的效果。完全不需要递归，只需要简单的判断</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就行，性能自然是非常好的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们甚至可以以非常简单的</SPAN><SPAN lang=EN-US>SQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句获得某一个</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>User</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>6</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>PermissionsValue</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">DECLARE @PermissionsValue int;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT @PermissionsValue = @PermissionsValue | PermissionsValue <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">FROM PermissionsOfRole WHERE<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">RoleID IN <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">(<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT ID FROM Role WHERE <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">LeftIndex &gt;= (SELECT LeftIndex FROM Role WHERE ID IN <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">(SELECT RoleID FROM UsersInRoles WHERE UserID = 2))<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">AND<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">RightIndex &lt;= (SELECT RightIndex FROM Role WHERE ID IN<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">(SELECT RoleID FROM UsersInRoles WHERE UserID = 2))<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">AND<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">ResourceID IN<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">(<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT ID FROM Resource WHERE<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">LeftIndex &lt;= (SELECT LeftIndex FROM Resource WHERE ID = 6)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">AND<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">RightIndex &gt;= (SELECT RightIndex FROM Resource WHERE ID = 6)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">SELECT @PermissionsValue;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上面的</SPAN><SPAN lang=EN-US>SQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">虽然有不少嵌套的</SPAN><SPAN lang=EN-US>SELECT</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，但是，因为子查询基本上都是对主键字段的条件判断，</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们也会加上索引，因此，实际上不会对性能造成太大影响。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>OK</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，查询性能很好，不过这是以新建或修改</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的层级关系时的一定的性能损失为代价的。每次新增或修改</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的层级关系时，必须按照前面所述的规则重置所有节点的</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值。不过，一般情况下，由于</SPAN><SPAN lang=EN-US>Role</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Resource</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的维护操作占系统整体操作的比例很小，几乎可以忽略，因此其性能损失也不是什么大问题。具体的重置所有节点</SPAN><SPAN lang=EN-US>LeftIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>RightIndex</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值的伪代码我就不贴出来了，大家稍微花费几个脑细胞就能想出来了</SPAN><SPAN lang=EN-US>^-^</SPAN></P>
<P>//结束</P><img src ="http://www.cnblogs.com/teddyma/aggbug/1050627.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41075/" target="_blank">[新闻]深藏33年Unix操作系统bug被消灭</a>]]></description></item><item><title>NBearLite PetShop 4.0示例源码</title><link>http://www.cnblogs.com/teddyma/archive/2008/01/09/1031975.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Wed, 09 Jan 2008 06:44:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2008/01/09/1031975.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/1031975.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2008/01/09/1031975.html#Feedback</comments><slash:comments>34</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/1031975.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/1031975.html</trackback:ping><description><![CDATA[摘要: 该示例使用NBearLite v1.0.1.2，基于.Net PetShop 4.0的源码修改。使用NBearLite重写了等价功能的BLL、Profile、Membership模块的数据访问部分，去除了DALFacrory、IDAL等工程（因为基于NBearLite可以透明的在多种数据库源间进行无缝切换，无需修改代码），去除了Order的基于MSMQ的异步处理部分。本示例演示了使用NBearLite作为数据访问组件进行开发的常用方法。Web工程的Web.config中默认关闭了CaceDependency，并设置了Sqlite为默认数据库。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2008/01/09/1031975.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/1031975.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41074/" target="_blank">[新闻]Expression Studio 2.0 中文版发布了</a>]]></description></item><item><title>基于CodeGenerator的Emit代码生成辅助类源码及演示</title><link>http://www.cnblogs.com/teddyma/archive/2007/10/10/919449.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Wed, 10 Oct 2007 03:56:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/10/10/919449.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/919449.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/10/10/919449.html#Feedback</comments><slash:comments>14</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/919449.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/919449.html</trackback:ping><description><![CDATA[摘要: 本文介绍一组NBearV4中的基于Emit动态生成代码的辅助类，部分概念在本人的blog之前的文章中或多或少都有介绍，这里包含最新的更新及演示、测试。主要是两个类：CodeGenerator和DynamicMethodFactory。前者提供了一种经过封装的，简化Emit方法（包括Emit DynamicMethod，Constructor，Method，get、set Method of Property）的方案；后者基于前者，实现了一种访问指定类（可以是第三方程序集的internal类）的方法或成员变量，实例化第三方程序集中的internal类型，高性能的以非泛型语法访问泛型方法的机制（通过DynamicMethod和Delegate实现）。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/10/10/919449.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/919449.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41073/" target="_blank">[新闻]雅虎首页大变脸 阿里风格上身</a>]]></description></item><item><title>扩展Kevin McFarlane的C#版DesignByContract Framework</title><link>http://www.cnblogs.com/teddyma/archive/2007/10/05/914656.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Fri, 05 Oct 2007 07:01:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/10/05/914656.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/914656.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/10/05/914656.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/914656.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/914656.html</trackback:ping><description><![CDATA[摘要: Kevin McFarlane的C#版DesignByContract Framework实现从02年在CodeProject发布至今，几乎成为C#开发中大多数朋友使用的事实标准。本文结合对该框架的使用经验，在Kevin的原始版本的基础上，使用Strategy Pattern对其进行进一步的扩展，对最常用的检查语义进行封装简化。本文改进的源码以Public Domain协议发布，也就是说，完全没有任何限制。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/10/05/914656.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/914656.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37598/" target="_blank">[新闻]万名Linux使用者向暴雪请愿Linux版《Diablo III》</a>]]></description></item><item><title>发布NBearLite中文版完全参考手册 + NBearLite 10分钟入门教程 + NBearLite v1.0.0.7 beta</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/29/835412.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Sun, 29 Jul 2007 07:12:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/29/835412.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/835412.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/29/835412.html#Feedback</comments><slash:comments>20</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/835412.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/835412.html</trackback:ping><description><![CDATA[摘要: NBearLite是一个.NET 2.0开源(BSD协议)通用数据访问组件，支持SQL Server、Oracle、MS Access，MySQL，SQLite，PostgreSQL等多种数据库的透明切换（改变数据库类型时无需修改具体的查询代码）。NBearLite实现了一套类似LINQ的强类型数据库查询语法(支持从简单的CRUD查询到GroupBy、InnerJoin，Paging，SubQuery等常用复杂查询)。NBearLite提供的代码生成工具还可以为您自动生成所有的存储过程调用包装代码，可以让您像使用一个.NET类的方法一样访问存储过程（支持SQL Server，Oracle，MySQL，PostgreSQL数据库）。<br><br>NBearLite不是一个ORM工具，它不涉及实体类，NBearLite的所有查询返回Scalar/DataSet/IDataReader等ADO.NET原生数据类型。<br><br>推荐在使用NBearLite的同时结合使用NBearMapping进行IDataReader/DataRow数据类型和自定义.NET类(如：实体类或业务类&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/29/835412.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/835412.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37597/" target="_blank">[新闻]56.com我乐网将全面转行 退出视频行业</a>]]></description></item><item><title>再续NBear性能测试:ADO.NET, NBearV3, NHibernateV1, NBearLite, NBearLite+NBearMapping性能比较[2008/1/3修订：NBearLite更新至v1.0.1.0整合NBearMapping版地测试结果]</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/26/831646.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Thu, 26 Jul 2007 00:15:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/26/831646.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/831646.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/26/831646.html#Feedback</comments><slash:comments>27</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/831646.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/831646.html</trackback:ping><description><![CDATA[摘要: 本测试对ADO.NET, NBearV3, NHibernateV1, NBearLite, NBearLite+NBearMapping进行了常见的读写测试。本测试同时证实，NBearLite及NBearLite+NBearMapping的ORM方案，平均性能有很大改善。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/26/831646.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/831646.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37596/" target="_blank">[新闻]Joost借道TOM在线 将正式进军中国</a>]]></description></item><item><title>NBearMapping - 开源通用对象映射组件v1.0.0.2 beta - 支持枚举类型字段</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/25/830863.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Wed, 25 Jul 2007 07:23:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/25/830863.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/830863.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/25/830863.html#Feedback</comments><slash:comments>17</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/830863.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/830863.html</trackback:ping><description><![CDATA[摘要: NBearMapping是NBearV4框架的组件之一，可以独立使用。可用于任意类型对象、DataRow和DataReader对象间的透明映射。建议结合NBearLite使用。<br>主要功能：<br>1、任意类型对象、DataRow和DataReader对象间的透明映射；<br>2、支持.NET的Nullable类型；<br>3、较高的性能，性能比基于Reflection的等价转换快约50%，手动代码 vs NBearMapping vs Reflection对象转换的执行时间比大约为1:2.5:3.6，可参见源码中MappingTest.TestPerformance() 测试；&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/25/830863.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/830863.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37595/" target="_blank">[新闻]微软副总裁公开承认Vista存在问题</a>]]></description></item><item><title>发布NBearLite v1.0.0 beta - 全面支持SqlServer，Oracle，MySql，PostgreSql数据库存储过程调用代码生成（C#/VB.NET）</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/23/828356.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Mon, 23 Jul 2007 07:08:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/23/828356.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/828356.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/23/828356.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/828356.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/828356.html</trackback:ping><description><![CDATA[摘要: NBearLite 更新至v1.0.0.6 beta <br>全面支持SqlServer，Oracle，MySql，PostgreSql数据库存储过程调用代码生成（C#/VB.NET），支持输入、输出、返回等各种参数类型。<br>支持Sub Query。<br>支持Save DataTable/DataRow。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/23/828356.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/828356.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37594/" target="_blank">[新闻]互联网DNS存在重大漏洞 黑客可能控制网络流量</a>]]></description></item><item><title>NBearV4预告及开发团队成员征集</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/22/827346.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Sun, 22 Jul 2007 07:01:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/22/827346.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/827346.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/22/827346.html#Feedback</comments><slash:comments>16</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/827346.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/827346.html</trackback:ping><description><![CDATA[摘要: 未来的NBearV4将由ORM、SOA、WEB等几个可无缝拼接，也可独立使用或搭配第三方组件模块使用的模块组成的全新构架的开发框架。。。。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/22/827346.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/827346.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37593/" target="_blank">[新闻]Opera提出网络标准课程 发布标准教育倡议</a>]]></description></item><item><title>发布NBearLite v1.0.0: 提供强类型查询语法的非ORM数据访问组件 [8/2 更新至v1.0.0.9 beta - 修复NBearLite参考手册某些操作系统打开错误的问题]</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/20/825384.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Fri, 20 Jul 2007 05:15:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/20/825384.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/825384.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/20/825384.html#Feedback</comments><slash:comments>45</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/825384.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/825384.html</trackback:ping><description><![CDATA[摘要: NBearLite是一个基于NBear的强类型查询内核的.NET 2.0开源通用数据访问组件。由NBear.org及Teddy维护。NBearLite继承了和进一步简化扩展了NBear中类似LINQ的强类型数据库查询语法(支持CRUD简单查询及GroupBy、InnerJoin，Paging等常用复杂查询)，简化了命名空间、代码架构，并进一步简化了用户使用，对已有代码也没有任何侵入。NBearLite不是一个ORM工具，它不涉及实体类，NBearLite的所有查询返回Scalar/DataSet/IDataReader。<br>&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/20/825384.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/825384.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37592/" target="_blank">[新闻]SubSonic 2.1 版本发布</a>]]></description></item><item><title>YetAnotherForum.Net+ScrewTurn Wiki中文完美汉化增强版(07-16更新：升级到v1.2.3 新增显示论坛版主信息，修复Wiki中文搜索)(GPL协议源码发布)</title><link>http://www.cnblogs.com/teddyma/archive/2007/07/12/813249.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Thu, 12 Jul 2007 07:14:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/07/12/813249.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/813249.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/07/12/813249.html#Feedback</comments><slash:comments>108</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/813249.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/813249.html</trackback:ping><description><![CDATA[摘要: 本程序是Teddy为更方便的收集整理各种育儿知识，准备架一个育儿论坛+Wiki网站5JBB.COM，而对YetAnotherForum.Net最新的version 1.9.1 RC1 (NET v2.0) - 2007-5-16版本和ScrewTurn Wiki最新的version 2.0.11 - 2007-7-3版本做的汉化，整合，Bug修复和功能增强。这里将完整的程序源码共享给大家，这是真正免费(GPL协议)，功能强大、稳定的ASP.NET 2.0中文论坛+Wiki程序哟！<br><br>谨以此程序献给我的宝贝女儿笑笑和所有初为新爹新妈的程序员朋友~~&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/07/12/813249.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/813249.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37590/" target="_blank">[新闻]语义搜索领跑后google搜索引擎</a>]]></description></item><item><title>绑定Enum到ASP.NET数据绑定控件的完美解决方案[05/26修订]——增加支持第三方枚举描述，支持二进制与过的枚举值</title><link>http://www.cnblogs.com/teddyma/archive/2007/05/26/759842.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Fri, 25 May 2007 23:44:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/05/26/759842.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/759842.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/05/26/759842.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/759842.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/759842.html</trackback:ping><description><![CDATA[摘要: 本文向读者介绍NBear中实现的DropDownListField字段绑定控件和EnumDescriptionAttribute特性。结合使用这两个组件，就可以最简单、易用和可扩展地完美解决绑定Enum到ASP.NET数据绑定控件的问题。[05/26修订]——增加支持第三方枚举描述，支持二进制与过的枚举值。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/05/26/759842.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/759842.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37586/" target="_blank">[新闻]2008年7月9日科技博客精选</a>]]></description></item><item><title>基于NBear的快速开发解决方案</title><link>http://www.cnblogs.com/teddyma/archive/2007/05/18/NBearSolution.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Fri, 18 May 2007 07:30:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/05/18/NBearSolution.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/751549.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/05/18/NBearSolution.html#Feedback</comments><slash:comments>39</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/751549.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/751549.html</trackback:ping><description><![CDATA[摘要: NBear是一个.Net 2.0下的快速开发框架。它提供了包括可视化实体设计、代码生成、持久化、SOA、MVP等一系列组件。<br>NBear的设计目标是尽最大可能减少程序员的重复劳动、提高开发效率、提升代码的可维护性和整体质量。<br>官方网站：http://nbear.org<br>中文教程目录索引：http://www.cnblogs.com/teddyma/archive/2006/11/07/553562.html<br>示例程序：从官方网站下载NBearVXXX_tutorials.zip，解压后见tutorials目录。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/05/18/NBearSolution.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/751549.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37585/" target="_blank">[新闻]Google推出免费虚拟现实服务 用户至少13岁</a>]]></description></item><item><title>NbearV3.7新增强类型查询功能演示教程</title><link>http://www.cnblogs.com/teddyma/archive/2007/04/24/725570.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Tue, 24 Apr 2007 09:11:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/04/24/725570.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/725570.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/04/24/725570.html#Feedback</comments><slash:comments>41</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/725570.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/725570.html</trackback:ping><description><![CDATA[摘要: 本教程演示了NBear中典型的的各种查询功能。包括：join，group by，paging等的支持。<br>下载地址：http://nbear.org/Modules/Articles/Detail.aspx?i=59&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/04/24/725570.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/725570.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37584/" target="_blank">[新闻]微软扩大企业在线应用 每年收$180远高于Google</a>]]></description></item><item><title>源码发布 - DynamicMethodProxyFactory组件</title><link>http://www.cnblogs.com/teddyma/archive/2007/03/28/690946.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Wed, 28 Mar 2007 03:10:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/03/28/690946.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/690946.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/03/28/690946.html#Feedback</comments><slash:comments>24</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/690946.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/690946.html</trackback:ping><description><![CDATA[摘要: 在前面的文章改进的“以非泛型方式调用泛型方法”之基于DynamicMethod的实现中，提到了一种通过DynamicMethod以非泛型方法代理访问泛型方法的较佳方法（无额外代码定义需要，执行时间大约相当于直接调用泛型方法的3-4倍）。本文介绍的组件在前文思路的基础上，进行进一步的扩展，封装成一个较通用的DynamicMethodProxyFactory组件。除了可以较高性能访问任意的静态或非静态、泛型或非泛行方法之外，利用DynamicMethod可将代码插入内存中已载入的Module的能力，提供了在程序集外实例化指定Module中的internal类型，在程序集外调用internal类型的方法和public类型的internal方法的支持。<br><br>该组件实现如下功能：<br>1、以通用的非泛行方法Delegate访问任意方法（泛型或非泛型，静态或非静态）；<br>2、支持在程序集外调用指定Module中的internal类型的任意属性（属性本质上可以通过它的get/set方法以方法的形式访问）和方法和public类型的internal方法；<br>3、支持创建并返&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/03/28/690946.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/690946.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37583/" target="_blank">[新闻]当Facebook开始引入个人三维空间</a>]]></description></item><item><title>改进的“以非泛型方式调用泛型方法”之基于DynamicMethod的实现</title><link>http://www.cnblogs.com/teddyma/archive/2007/03/22/684306.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Thu, 22 Mar 2007 09:06:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2007/03/22/684306.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/684306.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2007/03/22/684306.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/684306.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/684306.html</trackback:ping><description><![CDATA[摘要: 本文针对双鱼座同志的以非泛型方式调用泛型方法一文，提出一种更通用的以非泛型方式调用泛型方法的实现——基于DynamicMethod的实现。<br>基于DynamicMethod的实现的优点是，执行性能和双鱼座的文中实现的第5种方案——动态生成的非泛型接口包装相当（因为都是基于Emit的），但是，避免了原文实现中必须额外定义接口、Delegate的需要，从而，非常通用，应该是解决相同问题的前提下目前所能想到最佳实现。&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2007/03/22/684306.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/684306.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37582/" target="_blank">[新闻]最新操作系统市场占有率报告</a>]]></description></item><item><title>ADO.NET、NBear和NHibernate简单读写性能比较</title><link>http://www.cnblogs.com/teddyma/archive/2006/12/29/607271.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Fri, 29 Dec 2006 10:14:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2006/12/29/607271.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/607271.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2006/12/29/607271.html#Feedback</comments><slash:comments>29</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/607271.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/607271.html</trackback:ping><description><![CDATA[<br><a style="COLOR: #0000ff" href="http://nbear.org/download/NBear_VS_NH_Performance.zip">下载测试示例程序</a><br><br><strong>说明：</strong><br><br>本测试使用SqlServer2000的Northwind数据库的Categories、Customers和Products三个表，测试比较ADO.NET、NBear和NHibernate的读写性能。公平起见，测试代码并没有使用太多特别框架的独有功能或缓存，在实际测试前分别都进行了预读（保证元数据等都在第一次运行时已载入）。<br><br>读测试每次循环分别读取Categories、Customers和Products三个表的全部数据，三个组件分别返回DataSet，强类型实体数组和IList，虽然返回的数据类型不同，但是，实际上都包括了对返回数据的填充操作，因此，应该是相对公平的。结果显示NBear的性能近似于ADO.NET；NHibernate的独性能要差5倍左右。<br><br>写测试每次循环分别新建、更新并删除Categories、Customers和Products三个表中的各一条记录。ADO.NET由于是直接执行SQL的，速度最快是肯定的。NBear相比ADO.NET慢约3倍，NHibernate则大约慢2倍。<br><br>鉴于一般的系统读操作的频率远高于写操作，NBear的平均性能应该要比NHibernate好处不少。<br><br>测试并不完全，仅作参考。<br><br>
<div>
<h2>Read Performance Comparison</h2>
<table border=1>
    <tbody>
        <tr>
            <th>Repeat Times</th>
            <th>ADO.NET (ms)</th>
            <th>NBear (ms)</th>
            <th>NHibernate (ms)</th>
        </tr>
        <tr>
            <td>1</td>
            <td>218</td>
            <td>234</td>
            <td>1140</td>
        </tr>
        <tr>
            <td>2</td>
            <td>484</td>
            <td>515</td>
            <td>3812</td>
        </tr>
        <tr>
            <td>5</td>
            <td>1109</td>
            <td>1218</td>
            <td>6078</td>
        </tr>
        <tr>
            <td>10</td>
            <td>2218</td>
            <td>2484</td>
            <td>12390</td>
        </tr>
    </tbody>
</table>
<hr>
<h2>Write Performance Comparison</h2>
<table border=1>
    <tbody>
        <tr>
            <th>Repeat Times</th>
            <th>ADO.NET (ms)</th>
            <th>NBear (ms)</th>
            <th>NHibernate (ms)</th>
        </tr>
        <tr>
            <td>20</td>
            <td>125</td>
            <td>312</td>
            <td>234</td>
        </tr>
        <tr>
            <td>40</td>
            <td>203</td>
            <td>656</td>
            <td>437</td>
        </tr>
        <tr>
            <td>100</td>
            <td>546</td>
            <td>1609</td>
            <td>1046</td>
        </tr>
        <tr>
            <td>200</td>
            <td>984</td>
            <td>3046</td>
            <td>2015</td>
        </tr>
    </tbody>
</table>
</div>
<img src ="http://www.cnblogs.com/teddyma/aggbug/607271.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37587/" target="_blank">[新闻]PCWorld：Google到底要干什么？</a>]]></description></item><item><title>Suggested NBear Framework Based FDD Development Steps</title><link>http://www.cnblogs.com/teddyma/archive/2006/12/28/606483.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Thu, 28 Dec 2006 13:38:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2006/12/28/606483.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/606483.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2006/12/28/606483.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/606483.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/606483.html</trackback:ping><description><![CDATA[<p><strong>Suggested NBear Framework Based FDD Development Steps<br></strong><br>1. Collect Requirements.</p>
<p>2. Define Features according to Collected Requirements.</p>
<p>3. Define Entity Designs according to Defined Features.</p>
<p>4. Generate Entities, Configurations and Database Automatically from Entity Designs Using Code Generating Tools Provided by NBear.</p>
<p>3. Split Features into Clips from Presentation View Using Entities and Domain Objects (Value Objects).</p>
<p>4. Define MVP (Model/View/Presenter) Interfaces for Feature Clips using Entities.</p>
<p>5. Implement and Test Models, Views and Presenters asychronally Using Mock Tool to Simulate Implementations of Non-Implemented MVP Interfaces during separated development.</p>
<p>6. Integrate and Test MVPs in Together.</p>
<p>7. Finish.</p>
<p><br><strong>Benefits When Using NBear<br></strong><br>1. Minimize Manual Development and Maintenance Code Benefited from Code Generating Tool Provided By NBear.</p>
<p>2. Complete Team Parallel Development Support and Testable Presentaion Layer Benefited from MVP Pattern and NBear's MVP Components.</p>
<p>3. Strong Typed ORM (Object Relational Mapping) Support Benefited from NBear's Data Components. (No Manual Code or Configuration Needed.)</p>
<p>4. Strong Typed Distributed Support Benefited from NBear's IoC Components. (Configuration Only, No Manual Code Needed.)</p>
<p>5. Extended Web Helper Methods (String Formatter/AJAX/Client Script Factory, etc) to ASP.NET 2.0 Benefited from NBear's Web Components.</p>
<p>6. Transparent Code Generating and Database Synchronization in Visual Studio 2005 IDE Benefited from NBear's Visual Studio 2005 Code Generating Plugin.<br></p>
<img src ="http://www.cnblogs.com/teddyma/aggbug/606483.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37581/" target="_blank">[新闻]校内网宣布开放平台 陈一舟称将优先推招聘服务</a>]]></description></item><item><title>NBearV3.3.7 发布 - 震撼人心的VsPlugin来了！</title><link>http://www.cnblogs.com/teddyma/archive/2006/12/02/580078.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Sat, 02 Dec 2006 13:26:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2006/12/02/580078.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/580078.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2006/12/02/580078.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/580078.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/580078.html</trackback:ping><description><![CDATA[<a style="COLOR: #0000ff" href="http://sf.net/projects/nbear"><strong>从SF.NET下载最新版本NBearV3.3.7 stable<br></strong></a><br>VsPlugin使用教程参见：<a id=_211d59c50dbd_HomePageDays_DaysList_ctl04_DayItem_DayList_ctl00_TitleUrl href="http://www.cnblogs.com/teddyma/archive/2006/12/02/580075.html"><font style="COLOR: #0000ff" color=#0000ff><strong>NBearV3——VsPlugin使用教程</strong></font></a><br><br>
<img src ="http://www.cnblogs.com/teddyma/aggbug/580078.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37580/" target="_blank">[新闻]七月开发语言排行榜出炉 PowerShell有望成为年度黑马</a>]]></description></item><item><title>NBearV3教程——Cache篇</title><link>http://www.cnblogs.com/teddyma/archive/2006/11/21/565602.html</link><dc:creator>Teddy's Knowledge Base</dc:creator><author>Teddy's Knowledge Base</author><pubDate>Tue, 21 Nov 2006 02:17:00 GMT</pubDate><guid>http://www.cnblogs.com/teddyma/archive/2006/11/21/565602.html</guid><wfw:comment>http://www.cnblogs.com/teddyma/comments/565602.html</wfw:comment><comments>http://www.cnblogs.com/teddyma/archive/2006/11/21/565602.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cnblogs.com/teddyma/comments/commentRss/565602.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/teddyma/services/trackbacks/565602.html</trackback:ping><description><![CDATA[摘要: 本教程介绍NBearV3中的查询缓存支持。通过本教程，读者应能够全面掌握内置于NBearV3的查询缓存的使用。<br><br>&nbsp;&nbsp;<a href='http://www.cnblogs.com/teddyma/archive/2006/11/21/565602.html'>阅读全文</a><img src ="http://www.cnblogs.com/teddyma/aggbug/565602.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37579/" target="_blank">[新闻]阿里巴巴软肋明显 网盛携低会员价细分B2B市场</a>]]></description></item></channel></rss>