2

I need to add a RowVersion column to all my tables. I need it for reasons like data warehousing (and similar DB only actions). I don't want to use it for concurrency.

I want Entity Framework to keep working as if the RowVersion column is not there. But I can't seem to see a way to do that.

When ever I do an update, SQL Profile tells me this is what is being executed:

update [dbo].[Widget]
set [WidgetCost] = @0
where ([WidgetId] = @1)

select [RowVersionId]
from [dbo].[Widget]
where @@ROWCOUNT > 0 and [WidgetId] = @1

If I don't have the RowVersion column on the table then the second select statement does not happen.

How can I get Entity Framework to just ignore the RowVersionId column? If at all possible I would prefer a method that does not require manually editing the csdl/msdl after each update of the model from the database. (Someone will forget eventually.)

I have tried:

  1. Ensuring that the RowVersionId column's Concurrency Mode is set to "None"
  2. Deleting the RowVersionId column from the edmx. (I can't seem to delete it from the model.)

NOTE: As long as I don't update the table in EF's designer (edmx) after I add the column, it works as expected. So there is something in Entity Framework that this doing this. (But I can't just lock down my edmx from begin updated after I add this column.)

Vaccano
  • 78,325
  • 149
  • 468
  • 850
  • Been a while since I used edmx, but can you exclude the columns after refreshing the model? – DavidG Jun 23 '15 at 00:34
  • What is your problem with `RowVersion` column in Db-First workflow? Is a Concurrency exception thrown? – Alireza Jun 23 '15 at 09:33
  • @DavidG I can remove it from the editor, but not the model. – Vaccano Jun 23 '15 at 13:38
  • @Alireza my problem is only that it runs that extra query. My application runs in a very performance constrained environment. That extra lookup slows it down too much. – Vaccano Jun 23 '15 at 13:40

2 Answers2

0

I looked into this a bit more. If you change the StoreGeneratedPattern for the RowVersion column from "Computed" to "None", then it will not do the extra lookup.

Vaccano
  • 78,325
  • 149
  • 468
  • 850
0

Remove RowVersion field from your model class and it's mapping too