views:

22

answers:

1

I've created table with timestamp field. Allow Nulls property is set to false.
When I want to update entity from repository, I get null value for that field, but in databse this field is set to some value.
Does anyone knows what may be the problem?
I get the correct values for other fields.
Thank you.

edit:
When I get entity from the repository, timestamp field is set appropriately.
Problem is somewhere in http post:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Product product)

The value of timestamp field is lost here :(

A: 

By default, the Edit view that VS generates excludes binary fields. To include a Timestamp field in the view, you'll have to add to your view a hidden field like this one:

<%: Html.Hidden("Timestamp", Model.Timestamp.ToString()) %>

You'll also have to add this line to your Web.config if you get a compilation error like I did (using VS 2010):

<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

because Timestamp.ToString() is an extension method.

Keep in mind that you cannot explicitly change a timestamp field in the database. SQL Server manages that.