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

时间:2016-04-15 21:43:46   收藏:0   阅读:2147

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!