我的表有一个名为"RowVer"的时间戳列,LINQ将其映射到类型System.Data.Linq.Binary。对我来说,这种数据类型似乎是无用的,因为(除非我漏了什么),我无法像这样做:
// Select all records that changed since the last time we inserted/updated.
IEnumerable<UserSession> rows = db.UserSessions.Where
( usr => usr.RowVer > ???? );
因此,我正在考虑的解决方案之一是添加一个名为RowTrack的新“计算列”,该列在SQL中定义如下:
CREATE TABLE UserSession
(
RowVer timestamp NOT NULL,
RowTrack AS (convert(bigint,[RowVer])),
-- ... other columns ...
)
这让我可以按照自己的意愿查询数据库:
// Select all records that changed since the last time we inserted/updated.
IEnumerable<UserSession> rows = db.UserSessions.Where
( usr => usr.RowTrack > 123456 );
这是一种不好的做法吗?在查询计算列时性能如何?有更好的解决方法吗?
另外,我正在开发针对Sql Server 2000的应用程序以实现最大限度的向后兼容性,但我可以说服老板将2005作为最低公共分母。