简体   繁体   English

SQL Server RowVersion

[英]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: 我希望将它包含在我的下一个数据库中(现在设计它),我正在考虑两种不同的方式:

  1. RowVersion row in all tables 所有表中的RowVersion行
  2. A separate RowVersion table which has the ID of the table as a foreign key and linked to it. 一个单独的RowVersion表,它将表的ID作为外键并链接到它。

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.

相关问题 将 sql server rowversion 转换为 long 或 ulong? - converting sql server rowversion to long or ulong? 使用 EF Core 3.1 在 SQL Server 上生成不可为空的行版本 - Generating non-nullable rowversion on SQL Server with EF Core 3.1 Microsoft SQL Server Management Studio说RowVersion是无效类型 - Microsoft SQL Server Management Studio says that RowVersion is invalid type 如何从SQLDataReader到C#变量读取Rowversion或时间戳记SQL Server数据类型 - How Do I Read A Rowversion or Timestamp SQL Server Data Type From a SQLDataReader to a C# Variable 将SQL Server ROWVERSION放入System.Data.Linq.Binary属性时,出现System.InvalidCastException - System.InvalidCastException when getting SQL Server ROWVERSION into System.Data.Linq.Binary property 无法使Dapper正确处理SQL RowVersion - Can't get Dapper to handle SQL RowVersion properly 如何使用Linq 2 SQL更新对象而没有行版本或时间戳? - How do you update an object with Linq 2 SQL without rowversion or timestamp? 如何在C#中比较/转换SQL rowversion字段数据 - How compare/cast SQL rowversion field data in C# EF4 与 SQL Compact 4,rowversion 在保存时不更新 - EF4 with SQL Compact 4, rowversion doesn't update on save Rowversion IsDBNull - Rowversion IsDBNull
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM