EF model first設置屬性爲NotMapped

 

model first中不提供設置屬性爲NotMapped(不保存到數據庫)的功能,設計器中添加的所有屬性都會保存到數據庫中。

model first模式下,若要將某個屬性設置爲不保存到數據庫,可以使用partial類,在該屬性上方加上NotMapped特性。

[NotMapped]
public int Age
{
    get
    {
        return DateTime.Now.Year - Birthday.Value.Year;
    }
}

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章