我正在使用Access 2003 VBA来处理制造物料清单的递归数据。我构建了一个类模块,让我的主表具有静态范围。这似乎简化了递归 - 当我遍历BOM时,它让我无需再次向下计数水平。我没有冗余地打开相同的记录集;我过滤了很多。
在开始这个之后,我阅读了关于对象关系建模的内容,并决定实例不是记录集,而是记录。然后该记录的字段可以是属性。经过大量的工作和许多大多数错误的胜利之后,我意识到这种方法没有任何好处,因为Access是基于表格的。
我的班级模块仍然像以前一样有用。我的问题是关于下面的两个替代版本。第一个使用两个实例(Parent,Child)。第二个使用一个,然后重用它。显然,第一个受ORM影响。
有没有理由选择其中一个而不是另一个?另外,请注意最后的斜体线:如果我不需要(因为我不需要有关父级的更多信息),这是否会改变答案?一般来说,任何人都可以帮我解决这个问题吗?
(请注意,我关闭记录集但不关闭类实例。我的理解是VBA实例关闭自己并让他们这样做是公认的做法。我似乎已经将伪代码带到了新的伪级别...目标是清晰,希望它有效。)
VERSION 1 Property Sub ReviewPart ( Parent_Part_ID ) Get Parent_Part_ID Create instance of Class --> Get recordset Filter Class recordset ( Parent_Part_ID ) Exploit Class recordset See if Parent_Part_ID has Childs If it does: Open recordset of Childs For each Child Get Child_Part_ID Create instance of Class --> Get recordset Filter Class recordset ( Child_Part_ID ) Exploit Class recordset See if Child_Part_ID has Childs If it does: Instance New ReviewPart ( Child_Part_ID ) Otherwise: Nothing; Move On Next Child Close recordset of Childs Otherwise: Move On Exploit Class recordset ( still points to parent )
VERSION 2 Property Sub ReviewPart ( Parent_Part_ID ) Get Parent_Part_ID Create instance of Class --> Get recordset Filter Class recordset ( Parent_Part_ID ) Exploit Class recordset See if Parent_Part_ID has Childs If it does: Open recordset of Childs For each Child Get Child_Part_IDCreate instance of Class --> Get recordsetFilter Class recordset ( Child_Part_ID ) Exploit Class recordset See if Child_Part_ID has Childs If it does: Instance New ReviewPart ( Child_Part_ID ) Otherwise: Nothing; Move On Next Child Close recordset of Childs Otherwise: Move On Filter Class recordset ( Parent_Part_ID ) Exploit Class recordset ( still points to parent )
答案 0 :(得分:1)
似乎前者从程序员的角度为您提供了更好的易用性,因为您可以简单地从您感兴趣的记录开始,并通过访问您开始使用的记录的属性轻松地根据关联记录。< / p>
另一方面,后者似乎更有效率,因为它并不悲观地加载可能与当前记录相关的每条记录。
第一种方法的一些潜在优化可能有助于它在保持易用性的同时提高第二种方法的效率:
希望有所帮助。
答案 1 :(得分:1)
您是否考虑过使用msdatashape提供程序和SHAPE语法来生成hierarchical ADO recordsets?