是否有包含 RowVersion 值的 Microsoft.SqlServer.Management.Smo.SqlDataType 的替代方案?
Microsoft.SqlServer.Management。 Smo.SqlDataType
枚举具有 timestamp
类型的值,但没有 rowversion
类型的值。我正在寻找程序集的更新版本或支持它的替代枚举类型。
现有枚举具有 Timestamp
值,但根据 rowversion
文档、timestamp
已“已弃用,并将在未来版本中删除”。我更喜欢避免使用已弃用的东西:)
The Microsoft.SqlServer.Management.Smo.SqlDataType
enum has a value for the timestamp
type but not rowversion
. I'm looking for an updated version of the assembly or an alternate enum type that supports it.
The existing enum has a value for Timestamp
, but according to the rowversion
documentation, timestamp
is "deprecated and will be removed in a future version". I prefer to avoid using deprecated things :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找不到任何表明
SqlDataType.Timestamp
已弃用的信息。您提供的链接表明,rowversion
的“timestamp
语法”在 T-SQL 中已弃用,您应该使用rowversion
来代替,但它由库维护者负责确保在他们的产品中实现正确的语法。如果时间戳语法在未来版本中实际上被删除,那么我确信该库将被更新,并且Timestamp
枚举值仍将向后兼容使用它的代码。由于它们不提供RowVersion
枚举值,我只使用Timestamp
。I can't find anything that indicates that
SqlDataType.Timestamp
is deprecated. The link you provide indicates that the "timestamp
syntax" forrowversion
is deprecated in T-SQL and that you should userowversion
instead, but it is up to the library maintainers to make sure that the correct syntax is implemented in their product. Should it come to pass that the timestamp syntax is actually removed in a future version, then I'm sure the library will be updated and theTimestamp
enumeration value will still be backward compatible for code that uses it. Since they don't provide aRowVersion
enumeration value, I would just useTimestamp
.快速回答:
不,您不需要使用其他类型。
Microsoft.SqlServer.Management.Smo。 SqlDataType
数据类型是正确使用的类型。尽管是旧式名称,Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp
是 SMO 针对行版本
。不推荐使用 SQL Sever DDL 语句中的类型名称“timestamp”。如果您的代码生成包含类型名称
timestamp
的 DDL 语句并将其发送到 SQL Server,则应更改代码以使用[rowversion][4]
。但是,如果您只是使用 SMO 或任何使用Microsoft.SqlServer.Management.Smo.SqlDataType
类型,您不会受到服务器端名称更改的影响。长答案:
我将在这里合并一些引用,以避免重新发明轮子。首先,来自 http://www.mssqltips.com/tip.asp?tip= 的一些历史记录第1501章
请注意,Oracle 和 Postgres 都以符合标准的方式使用 TIMESTAMP,因此 Microsoft 放弃非标准的时间戳用法是明智之举,以避免让 Oracle 开发人员在 SQL Server 上工作变得更加困难。
无论如何,从
timestamp
到rowversion
的更改只是名义上的。它不会影响使用该类型的列的行为。根据rowversion
的 MSDN 文档:如果您深入研究数据类型同义词的文档:
换句话说,当 SMO 获取有关表的元数据时,它只知道行版本。这意味着包含 rowversion 类型列的表将作为
Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp
SMO API 从未跟上 SQL Server 使用的新命名。但由于类型的底层行为没有改变,只有名称改变,所以您的 SMO 客户端代码不需要改变。
如果您的代码显示 SQL Server 数据类型,您可以成为一个好公民并更改该代码以显示“rowversion”而不是“timestamp”。但除此之外,您的代码根本不需要更改。事实上,大多数 SMO 客户端 (包括 Visual Studio 的表设计工具!)甚至从未费心更改其 UI 以反映新的命名。由于这些 UI 在幕后连接到枚举,因此无论 SQL Server 在 DDL 中调用什么类型,SMO API 客户端都将继续工作。
SMO API 的未来版本也可能会向枚举添加一个具有相同基础数值的同义值(例如 Microsoft.SqlServer.Management.Smo.SqlDataType.RowVersion),但前提是现有客户没有被破坏,这对他们来说可能是一个低优先级。
Quick answer:
No, you don't need to use another type.
Microsoft.SqlServer.Management.Smo.SqlDataType
datatype is the right type to use. Despite the old-style name,Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp
is the value returned by SMO for SQL Server columns of typerowversion
.What's being deprecated is the use of the type name "timestamp" in SQL Sever DDL statements. If your code is generating DDL statements containing the type name
timestamp
and sending them to SQL Server, you should change your code to use[rowversion][4]
instead. But if you're just using SMO or any of the types which use theMicrosoft.SqlServer.Management.Smo.SqlDataType
type, you won't be affected by the name change on the server side.Long Answer:
I'm going to combine a few quotes here to avoid re-inventing the wheel. First, some history from http://www.mssqltips.com/tip.asp?tip=1501:
Note that Oracle and Postgres both use TIMESTAMP in the standards-compliant way, so it's a smart move by Microsoft to ditch the non-standard usage of timestamp to avoid making things harder for Oracle devs trying to work on SQL Server.
Anyway, the change from
timestamp
torowversion
is in name only. It doesn't impact the behavior of columns using that type. Per the MSDN docs forrowversion
:If you dig into the docs for Data Type Synonyms:
In other words, by the time SMO gets ahold of the metadata about the table, it only knows about rowversion. This means that tables with columns of type rowversion are being returned to SMO as
Microsoft.SqlServer.Management.Smo.SqlDataType.Timestamp
The SMO API never caught up with the new naming used by SQL Server. But because the underlying behavior of the type didn't change, only the name, your SMO client code does not need to change.
If your code is displaying SQL Server data types, you can be a good citizen and change that code to display "rowversion" instead of "timestamp". But otherwise your code doesn't need to change at all. In fact, most SMO clients (including Visual Studio's table design tool!) never even bothered to change their UI to reflect the new naming. Because those UIs connect to the enum under the covers, the SMO API clients will continue working regardless of what SQL Server calls the type in DDL.
It's possible that a future rev of the SMO API might also add a synonymous value to the enum (e.g.
Microsoft.SqlServer.Management.Smo.SqlDataType.RowVersion
) with the same underlying numeric value, but given that existing clients aren't broken this is probably a low priority for them.