7.2 数据注解属性--TimeStamp特性【Code-First 系列】
TimeStamp特性可以应用到领域类中,只有一个字节数组的属性上面,这个特性,给列设定的是tiemStamp类型。在并发的检查中,Code-First会自动使用这个TimeStamp类型的字段。
下面让我们来看看代码吧:
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; }
[Timestamp]
public byte[] RowVersion { get; set; }
}
}
运行程序,得到的数据库是:


如果真苦,你哪有时间喊累。如果真惨,你哪有时间觉得丢脸。因为承受得还不够,所以你才有时间抱怨。人生总有太多的无奈和遗憾,因为这就是生活。

浙公网安备 33010602011771号