可以通过NotMappedAttribute标记模型某个属性可以使该属性不必映射到数据库。
public class Unicorn
{
public int Id { get; set; }
[NotMapped]
public string Name { get; set; } [Timestamp]
public byte[] Version { get; set; } public int PrincessId { get; set; } // FK for Princess reference
public virtual Princess Princess { get; set; }
}
NotMapped无效的时候,在DbContext的OnModelCreating方法重载中实现
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//不映射到数据库中
modelBuilder.Entity<BlogArticle>().Ignore(p => p.Title);
}