1
votes

Im using the Entity Framework and I have a rowversion (timestamp) field on a table to use for concurrency. However, when updating the entity object, it keeps trying to set the rowversion column to null, and I get an error:

The 'VerCol' property on 'LmpDemoRequest' could not be set to a 'null' value. You must set this property to a non-null value of type 'Byte[]'.

I have the VerCol column within the entity definition, but I am unable to remove the "Setter" function.

How do I get the entity framework to stop attempting to set this column?

2

2 Answers

4
votes

You can pass any arbitrary, valid values for the RowVersion fields (DateTime.Now for example). They will be overwritten with the server-generated values.

For future releases of EF, there should be support for "shadow properties", which exist in the model but not in your classes. That feature would be useful in situations such as this.

0
votes

I had a case where a view included a RowVersion column from a table that was left joined in the view... so that column could be null sometimes.

But EF4 'knows' that a RowVersion column cannot be null, so even in a simple LINQ query, it was throwing an InvalidOperationException:

The 'PersonRowVersion' property on 'vVoteInfo' could not be set to a 'DBNull' value. You must set this property to a non-null value of type 'Byte[]'

I finally had to change the view to use this for the RowVersion column, so that EF would be happy:

coalesce(p._RowVersion, cast(0 as binary(6))) [PersonRowVersion]