The first timestamp of an entity model

I am developing an application based on the Entity Framework. I use a model based approach. I would like to handle concurrency problems. As written in many articles, I am going to do this by turning ConcurrencyMode into a fixed field that is a timestamp. At the moment, I am faced with a problem - I can not add a field (column) of type timestamp. How can I do this in a model?

As written here:

http://social.msdn.microsoft.com/Forums/is/adodotnetentityframework/thread/1ed8d1e4-9d78-4593-9b10-33e033837af8 \

I tried installing the Entity Designer Database Generation Power Pack, but still I see no way to generate the timestamp from the model (I even tried to set it manually in the edmx file, but still I do not get the timestamp fcolumn in the generated database).

Please, help.

+6
source share
2 answers

I think the database type timestamp maps to the binary property type in EF.

My timestamp column is a model of type Binary with a length of 8 fixed at a length of true, StoreGenratedPattern is computed.

EDIT: This is actually not possible without changing the t4 template, as described here: Entity Framework timestamp. Creating a database problem

+2
source

EF 6.1, I have the following:

public partial class DepartmentEFEntity { Guid DepartmentUUID { get; set; } public byte[] TheVersionProperty { get; set; } } 

and then:

  modelBuilder.Entity<DepartmentEFEntity>().Property(o => o.TheVersionProperty).HasColumnType("timestamp").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed).IsRowVersion(); 

When I script out of the table, I get the following:

 CREATE TABLE [dbo].[Department]( [DepartmentUUID] [uniqueidentifier] NOT NULL, [TheVersionProperty] [timestamp] NOT NULL ) 
0
source

Source: https://habr.com/ru/post/910058/


All Articles