views:

726

answers:

1

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?

+3  A: 

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.

Koistya Navin
Surely you mean: "That should be a necessary feature for any ORM"
mendicant
This answer seems to work, thanks. I really, really hate how little things like this slip through into 'production ready' software. I'm a PHP guy trying to make a C#/ASP.NET MVC app, and stupid things like this, which should take a few seconds to figure out a solution too, take hours to solve.
Or you could just use NHibernate which has had all these problems solved and running production for over 5 years
chadmyers