Entity framework model first timestamp
Asked Answered
A

2

6

I am developing Entity Framework based app. I am using model-first approach. I would like to handle the concurrency issues. As written in many articles I am going to do it by turning the ConcurrencyMode to fixed on a field which is a timestamp. At the moment I am facing the problem - I cannot add field (column) of type timestamp. How can I do it in model?

As written here:

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

I tried installiing Entity Designer Database Generation Power Pack, but still I see no possibility to have the timestamp generated from the model (I have even tried setting it manually in edmx file, but still I am not receiving timestamp fcolumn in generated database).

Please help.

Azotic answered 6/3, 2012 at 9:27 Comment(0)
G
2

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

My model's timestamp column is type Binary with length 8, fixed length true, StoreGenratedPattern is Computed.

EDIT: Actually not possible without changing the t4 template as explained here: Entity Framework timestamp Generate Database issue

Griffey answered 10/4, 2012 at 2:14 Comment(0)
J
0

EF 6.1, I have this:

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 the table, I get this:

CREATE TABLE [dbo].[Department](
    [DepartmentUUID] [uniqueidentifier] NOT NULL,
    [TheVersionProperty] [timestamp] NOT NULL
    )
Joanne answered 4/12, 2013 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.