Jean Hominal
Jean Hominal

Reputation: 16796

Is it possible to map SQL Server's rowversion type to something friendlier than byte[] using Entity Framework?

When I declare a SQL Server rowversion field in the Storage Model and let Entity Framework do its default mapping, the rowversion field is mapped to a byte array.

Is it possible to map it to a friendlier type (that would allow expressing equality and comparison operators from the .NET side)? Given that the underlying type for rowversion is binary(8), I believe it may be possible to map it to a 64-bit integer.

Here are the property definitions currently used:

SSDL:

<Property Name="lastModifiedRowVersion" Type="timestamp" Nullable="false" StoreGeneratedPattern="Computed" />

CSDL:

<Property Name="LastModifiedRowVersion" Type="Binary" FixedLength="true" MaxLength="8" Nullable="false" ConcurrencyMode="Fixed" />

Upvotes: 1

Views: 1644

Answers (2)

Steve S
Steve S

Reputation: 624

I use a computed column for this. The ISNULL means that the EF POCO will be long rather than Nullable<long>.

...
Revision                ROWVERSION,
Revision64              AS ISNULL(CAST(Revision AS BIGINT), 0),
...

Upvotes: 0

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

Unfortunately it is not possible because EF doesn't have any kind of data conversion functionality. If you want to use 64bit integer you must still map byte array and expose second non mapped property converting array to integer. Here you have something more about comparing timestamp in application.

Upvotes: 1

Related Questions