Data annotation attribute -- TimeStamp feature [Code-First series], codefirst
The TimeStamp feature can be applied to the domain class and has only one byte array attribute. This feature sets the tiemStamp type for the column. In the concurrent check, Code-First will automatically use this TimeStamp type field.
Let's take a look at the Code:
using System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Linq;using System.Text;using System.Threading.Tasks;namespace EF2{ [Table("StudentInfo")] public class Student { [Key] [Column(Order=1)] public int StudentKey1 { get; set; } [Key] [Column(Order=2)] public int StudentKey2 { get; set; } [Column("Name",TypeName="ntext")] [MaxLength(20)] public string StudentName { get; set; } [NotMapped()] public int? Age { get; set; } public int StdId { get; set; } [ForeignKey("StdId")] public virtual Standard Standard { get; set; } 1449391548 public byte[] RowVersion { get; set; } }}
Run the program and obtain the following database: