in my ODATA service I use EF6 to work with SQL Server.
An EDMX is created also for the table Departments. In that table there is a TimeStamp field for Concurrency purposes. And yes I have added [Timestamp] data annotation in the code. And in the EDMX the field is FIXED for Concurrency Mode.
When I select a department in my website datagrid and update the field I get the message:
Cannot update a timestamp column.
In SQlProfiler I see the update passing:
exec sp_executesql N'UPDATE [dbo].[Department]
SET [ModificationDate] = @0, [ModifiedBy] = @1
WHERE (([Id] = @2) AND ([ModificationDate] = @3))
',N'@0 binary(8),@1 int,@2 int,@3 binary(8)',@0=0x0000000000000805,@1=27,@2=3,@3=0x0000000000000805
And then I notice the curious thing. It wants to update the ModificationDate field (Timestamp) while I want to update the field DepartmentName in the entity.
How can I overcome this strange behaviour?
I have set the Column to Computed and now the column is not added to the SET part of the query.
But why the field DepartmentName is not being set in the update query by EF?
What I have tried:
This is my code. The Departmentname is set! (SelectedEntity is set in the aspx.cs code when the RowUpdating command is being executed.
if (SelectedEntity == null)
SelectedEntity = new Department();
SelectedEntity = MarinGlobalConnection.MarinGlobalDataService._marinGlobal.Departments.First(x => x.Id == SelectedEntity.Id);
SelectedEntity.DepartmentName = afdelingNaam;
SelectedEntity.IsDeleted = isdeleted;
SelectedEntity.ModifiedBy = CurrentUser.Instance.CurrentConnected == null ? (int?)null : CurrentUser.Instance.CurrentConnected.ID;
if (SelectedEntity.Id == 0)