EF 解除属性映射到数据库中 NotMappedAttribute无效解决办法

可以通过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); 
}

 

 
文章来自:http://www.cnblogs.com/kennyliu/p/5396937.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3