gpt4 book ai didi

c# - smo 的 IsSystemObject 属性

转载 作者:太空狗 更新时间:2023-10-29 22:26:37 25 4
gpt4 key购买 nike

我正在使用 SMO 从数据库中获取存储过程列表。我对存储过程进行了 foreach 循环,以对它们进行预期的操作。但是我只需要使用用户创建的存储过程。我使用存储过程的 IsSystemObject 属性。但是它太慢了:

大约 10 秒:

foreach (StoredProcedure mystr in mydb.StoredProcedures)
{
if (!mystr.IsSystemObject)
{
classGenerated += mystr.Name + Environment.NewLine;
}
}

不到 1 秒:

foreach (StoredProcedure mystr in mydb.StoredProcedures)
{
classGenerated += mystr.Name + Environment.NewLine;
}

这种差异对于一个 if 条件是否正常?如果不是,造成这种性能差异的原因是什么?如果有其他方法,我可以使用另一种方法来区分系统对象和非系统对象。

最佳答案

是的。这就是为什么。默认情况下,SMO 预取某些属性并及时保留其他属性。因此,您基本上会为每个过程调用一次,以确定它是否是系统过程。幸运的是,有一个修复。查看this BOL article

SMO optimization allows only the minimum properties to be loaded when an object is created. When uninitialized properties are accessed, SMO makes individual requests to load the information from the instance of SQL Server. You can use this method to adjust which properties are initialized for an object when it is first created to further optimize performance

关于c# - smo 的 IsSystemObject 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20740561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com