[英]SQL Server RowVersion
Quick question Re: Implementation of RowVersion. 快速问题Re:RowVersion的实现。
I am looking to include it in my next database (Designing it now) and I am pondering 2 different ways: 我希望将它包含在我的下一个数据库中(现在设计它),我正在考虑两种不同的方式:
Anyone tried this? 有人试过吗? If so what pitfalls or pro's did you experience? 如果是这样,你遇到了什么陷阱或专业人士?
I will be using LINQ to access the data using C# 2008 and SQL Server 2008. 我将使用LINQ使用C#2008和SQL Server 2008访问数据。
Thanks, 谢谢,
James 詹姆士
If you are using LINQ to SQL then it is a good practice to include a timestamp / rowversion column for each entity table, as this allows LINQ to use optimistic concurrency very easily and results in slightly better performance for updates (as LINQ only has to query the timestamp column and does not have to compare other columns for changes). 如果您使用的是LINQ to SQL,那么为每个实体表包含一个时间戳/行转换列是一个好习惯,因为这样可以让LINQ非常轻松地使用乐观并发,并使更新的性能稍微提高(因为LINQ只需查询timestamp列,不必比较其他列进行更改)。
So go for the first option. 所以选择第一个选项。 The second option is a non-starter, really. 第二种选择是非首发,真的。
Add your rowversion to the primary table - putting it in a second table and linking to it will reduce performance. 将rowversion添加到主表 - 将其放在第二个表中并链接到它将降低性能。
As Sam said above, LINQ benefits from having rowversions on the table - but I don't think it will work with a linked table. 正如Sam上面所说的那样,LINQ可以从桌面上获得反转,但我认为它不适用于链接表。
Assume by RowVersion you mean timestamp (bad name) datatype. 假设由RowVersion表示时间戳(错误名称)数据类型。
Use a Rowversion column in all tables. 在所有表中使用Rowversion列。
SQLServer updates the column automatically. SQLServer自动更新列。
I have never used LINQ to SQL (like my SQL raw) but Rowversion column are very useful in updates (concurrency). 我从未使用过LINQ to SQL(就像我的SQL raw),但Rowversion列在更新(并发)中非常有用。
Just use "WHERE ID=@ID AND ROWVERSION=@RV" to handle concurrent updates. 只需使用“WHERE ID = @ ID AND ROWVERSION = @ RV”来处理并发更新。
Do NOT use your second option! 不要使用你的第二个选项!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.