What is the corresponding timestamp variable type (SQL Server) in C#?

Asked

Viewed 468 times

3

I have a field in the database (Seqalteracao) of type timestamp and need to map it to C# (Entity Framework).

What is the corresponding type in C# for this type in the bank?

 public **Tipo** SeqAlteracao { get; set; }

2 answers

6


You can use the type byte annotated TimeStamp

 [Timestamp]
 public byte[] RowVersion { get; set; }

Look at that one tutorial to better understand.

  • This totorial demonstrated well the use, was exactly what needed, because to use Dataannotations.

  • ah the S is minute [Timestamp]

  • 1

    I put minusculo! Thank you!

2

The normal and seemingly most obvious would be to use the DateTime, After all, the goal of both, roughly speaking, is the same, is to point a point in time. Each with a different representation, but the data is the same. And when we talk about data to be processed the representation doesn’t matter, it only matters when it goes out. Then read a timestamp and play in a DateTime.

Or don’t do it, because the specific purpose of the type timestamp SQL Server is actually for versioning and not exactly for saving a point in time. So only use so even if the SQL Server modeling was done wrong and used the wrong type.

The correct types in SQL Server when the intention is to save a time is the datetime and the datetime2. Actually even this is not perfect, since the semantics of each of the two and the type of C# do not match.

Be the intention to save a versioning even, use a long. Some even prefer to create their own kind.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.