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

3

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

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

 public **Tipo** SeqAlteracao { get; set; }
    
asked by anonymous 21.11.2016 / 21:00

2 answers

6

You can use type byte with annotation of TimeStamp

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

Look at this tutorial to better understand.

    
21.11.2016 / 21:10
2

The normal and what seems most obvious would be to use DateTime , after all the purpose of both, roughly, is the same, is to point a point in time. Each one with a different representation, but the data is the same. And when we talk about data to be processed the representation does not matter, it only matters when it's going to give a way out. Then read a timestamp and play on DateTime .

Or do not do this, because the specific purpose of timestamp type of SQL Server is actually to do versioning and not exactly to save a point in time. So just use it anyway if the SQL Server modeling was done wrong and used the wrong type.

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

If you intend to save a versioning yourself, use a long . Some people even prefer to create their own type.

    
21.11.2016 / 21:11