Entity Framework code first with TimeStamp type
Asked Answered
P

3

8

I am using SQL Server 2008 R2 and Entity Framework 5.0. When the database is generated, I cannot add my property of type TimeStamp without having the following error: There is no store type corresponding to the conceptual side type

'Edm.Time(Nullable=True,DefaultValue=,Precision=)' of primitive type 'Time'.

I have set the Entity Configuration to the type time or timestamp without success

Property(x => x.RestBetweenSet).HasColumnType("timestamp");

When I go in the Sql Server Management Studio and edit the table I can set a column of timestamp.

What do I need to do to have Entity Framework code first be able to generate this column?

Thank you

Pled answered 26/9, 2012 at 23:28 Comment(0)
P
3

For the moment, I map to a INT64 and ignore the TimeStamp. Like in this post.

If they are better solutions, feel free to add. I won't accept my answer yet.

Pled answered 1/10, 2012 at 13:12 Comment(1)
So you wanted to store a Timespan rather than a Timestamp?Tomtom
C
15

You should declare your time stamp property as follows in your code first class:

[Timestamp] 
public Byte[] MyTimestamp { get; set; }
Conduct answered 26/9, 2012 at 23:33 Comment(1)
Hi, the problem is that we cannot use anymore all timestamp method if it's a Byte.Pled
P
3

For the moment, I map to a INT64 and ignore the TimeStamp. Like in this post.

If they are better solutions, feel free to add. I won't accept my answer yet.

Pled answered 1/10, 2012 at 13:12 Comment(1)
So you wanted to store a Timespan rather than a Timestamp?Tomtom
C
1

I am not sure I understand your question so well, but this how I generate timestamp fields using code first approach and entity framework

[Required, DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime CreatedAt { get; set; }
Chart answered 16/3, 2017 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.